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
:私の合計を与える私はここで何が欠けていますか? そして違いを生むレコードを見つけるにはどうすればいいですか?
Control_Noは一意ですか? – Anton
いいえ、それは公布することができます – Oleg
この場合、その動作が必要です。私がいくつかのウェブサイトの訪問者であると想像してください。ホームと検索という2つのページを訪問しました。私はウェブサイトを訪問しただけで、他の訪問者はいません。 1ページあたりのユニークビジター数:検索= 1、ページ= 1。ウェブサイト全体のユニークビジター数はまだ1 + 1ではなく1です。それは理にかなっていますか? – Anton