I am doing an sql query where I retrieve a list over Accounts for a specific year. I thought the below code was fine.
SELECT count(DISTINCT ACCOUNT) AS ACCOUNT,
CASE when MONTH(Created)=1 then 'January'
when MONTH(Created)=2 then 'February'
when MONTH(Created)=3 then 'March'
when MONTH(Created)=4 then 'April'
when MONTH(Created)=5 then 'May'
when MONTH(Created)=6 then 'June'
when MONTH(Created)=7 then 'July'
when MONTH(Created)=8 then 'August'
when MONTH(Created)=9 then 'September'
when MONTH(Created)=10 then 'October'
when MONTH(Created)=11 then 'November'
when MONTH(Created)=12 then 'December'
else '3' end AS MONTH
FROM DB_Table
WHERE
AND (DB_Table.Cancelled < '1901-01-01' OR DB_Table Cancelled > '2017-12-31')
AND YEAR(Created)='2017'
GROUP BY MONTH(Created)
Order BY MONTH(Created)
Until I did a check this way:
Select count(DISTINCT ACCOUNT) AS ACCOUNT
FROM DB_Table
WHERE
AND (DB_Table.Cancelled < '1901-01-01' OR DB_Table Cancelled > '2017-12-31')
AND YEAR(Created)='2017'
I'm having two different sums, but it seems like the Group by is giving me a higher count than the bottom query. Any suggestions?