2016-10-10 11 views
0

私は基本的にどのように異なる結果セットを生成する同じ条件で同じクエリを理解できないのですか?私がやっているすべてはちょうどアモンサイズによってなぜ同じデータセットからのクエリが私に別の結果を与えるのですか?

--First query 
select count(distinct controlno) 
    FROM CatalyticWindEQ 
    WHERE EffectiveDate >='05-01-2016' AND EffectiveDate <= EOMONTH(GETDATE()) 
    AND LineName = 'Earthquake' 
    AND Underwriter <> 'Batcheller, Jerry' 
    AND DisplayStatus IN ('Bound','Bound - Issued') 
    and description IN ('New Business' 
         ,'Renewal' 
         ,'Rewrite') 

を破壊された合計数:708

--Second query 
     SELECT 
      'New' as Range, 
      COUNT(DISTINCT CASE WHEN BOUND_Premium <= 5000 AND Description = 'New Business' AND DisplayStatus IN ('Bound','Bound - Issued') THEN ControlNo END) AS '0-5K', 
      COUNT(DISTINCT CASE WHEN BOUND_Premium > 5000 and BOUND_Premium <=10000 AND Description = 'New Business' AND DisplayStatus IN ('Bound','Bound - Issued') THEN ControlNo END) AS '5K-10K', 
      COUNT(DISTINCT CASE WHEN BOUND_Premium > 10000 and BOUND_Premium <= 25000 AND Description = 'New Business' AND DisplayStatus IN ('Bound','Bound - Issued') THEN ControlNo END) AS '10K-25K', 
      COUNT(DISTINCT CASE WHEN BOUND_Premium > 25000 and BOUND_Premium <=50000 AND Description = 'New Business' AND DisplayStatus IN ('Bound','Bound - Issued') THEN ControlNo END) AS '25K-50K', 
      COUNT(DISTINCT CASE WHEN BOUND_Premium > 50000 AND Description = 'New Business' AND DisplayStatus IN ('Bound','Bound - Issued') THEN ControlNo END) AS '>50K' 
    FROM CatalyticWindEQ WHERE EffectiveDate >='05-01-2016' AND EffectiveDate <= EOMONTH(GETDATE()) AND LineName = 'Earthquake' AND Underwriter <> 'Batcheller, Jerry' 

UNION ALL 
     SELECT 
      'Renewal' as Range, 
      COUNT(DISTINCT CASE WHEN BOUND_Premium <= 5000 AND Description = 'Renewal' AND DisplayStatus IN ('Bound','Bound - Issued') then ControlNo END) AS '0-5K', 
      COUNT(DISTINCT CASE WHEN BOUND_Premium > 5000 and BOUND_Premium <=10000 AND Description = 'Renewal' AND DisplayStatus IN ('Bound','Bound - Issued') THEN ControlNo END) AS '5K-10K', 
      COUNT(DISTINCT CASE WHEN BOUND_Premium > 10000 and BOUND_Premium <= 25000 AND Description = 'Renewal' AND DisplayStatus IN ('Bound','Bound - Issued') THEN ControlNo END) AS '10K-25K', 
      COUNT(DISTINCT CASE WHEN BOUND_Premium > 25000 and BOUND_Premium <=50000 AND Description = 'Renewal' AND DisplayStatus IN ('Bound','Bound - Issued') THEN ControlNo END) AS '25K-50K', 
      COUNT(DISTINCT CASE WHEN BOUND_Premium > 50000 AND Description = 'Renewal' AND DisplayStatus IN ('Bound','Bound - Issued') THEN ControlNo END) AS '>50K' 


    FROM CatalyticWindEQ WHERE EffectiveDate >='05-01-2016' AND EffectiveDate <= EOMONTH(GETDATE()) AND LineName = 'Earthquake' AND Underwriter <> 'Batcheller, Jerry' 

UNION ALL 

     SELECT 
      'Rewrite' as Range, 
      COUNT(DISTINCT CASE WHEN BOUND_Premium <= 5000 AND Description = 'Rewrite' AND DisplayStatus IN ('Bound','Bound - Issued') then ControlNo END) AS '0-5K', 
      COUNT(DISTINCT CASE WHEN BOUND_Premium > 5000 and BOUND_Premium <=10000 AND Description = 'Rewrite' AND DisplayStatus IN ('Bound','Bound - Issued') THEN ControlNo END) AS '5K-10K', 
      COUNT(DISTINCT CASE WHEN BOUND_Premium > 10000 and BOUND_Premium <= 25000 AND Description = 'Rewrite' AND DisplayStatus IN ('Bound','Bound - Issued') THEN ControlNo END) AS '10K-25K', 
      COUNT(DISTINCT CASE WHEN BOUND_Premium > 25000 and BOUND_Premium <=50000 AND Description = 'Rewrite' AND DisplayStatus IN ('Bound','Bound - Issued') THEN ControlNo END) AS '25K-50K', 
      COUNT(DISTINCT CASE WHEN BOUND_Premium > 50000 AND Description = 'Rewrite' AND DisplayStatus IN ('Bound','Bound - Issued') THEN ControlNo END) AS '>50K' 

    FROM CatalyticWindEQ WHERE EffectiveDate >='05-01-2016' AND EffectiveDate <= EOMONTH(GETDATE()) AND LineName = 'Earthquake' AND Underwriter <> 'Batcheller, Jerry' 

結果は次のとおりです。722

:私の合計を与える enter image description here

私はここで何が欠けていますか? そして違いを生むレコードを見つけるにはどうすればいいですか?

+0

Control_Noは一意ですか? – Anton

+0

いいえ、それは公布することができます – Oleg

+1

この場合、その動作が必要です。私がいくつかのウェブサイトの訪問者であると想像してください。ホームと検索という2つのページを訪問しました。私はウェブサイトを訪問しただけで、他の訪問者はいません。 1ページあたりのユニークビジター数:検索= 1、ページ= 1。ウェブサイト全体のユニークビジター数はまだ1 + 1ではなく1です。それは理にかなっていますか? – Anton

答えて

0

私が見ていることから、できることは最高です。そのようなことが私に起こったとき、私は第2の要求で複数のカテゴリに現れたが、より一般的な要求によって排除されたレコードを複製しました。

関連する問題