Я не могу понять, как в принципе тот же запрос с теми же условиями, что и производящий другой набор результатов? Все, что я делаю, это просто нарушение вниз Amont размераПочему запрос из одного набора данных дает мне другой результат?
--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
Нет, это может быть dublicate – Oleg
В этом случае ожидается такое поведение. Только представьте, что я посетитель какого-то веб-сайта. Я посетил две страницы - «Дом и поиск». Только я посетил веб-сайты, других посетителей нет. Количество уникальных посетителей на странице: Search = 1, Page = 1. Количество уникальных посетителей на весь веб-сайт по-прежнему один, а не 1 + 1. Имеет ли это смысл? – Anton