Hi everyone,
I built a query that takes a person's date, and performs a count for each month.
Here's part of the query:
The query results is showing my months in alphabetical order. I want them sorted by calendar year so January would be the first.
Is there a way to do this?
I built a query that takes a person's date, and performs a count for each month.
Here's part of the query:
Code:
SELECT A.MONTHS,
A.YEAR,
COUNT(*)
FROM
(select A.SSN,
A.YEAR,
CASE
when A.MONTH = 1 then 'JANUARY'
when A.MONTH = 2 then 'FEBUARY'
when A.MONTH = 3 THEN 'MARCH'
WHEN A.MONTH = 4 THEN 'APRIL'
WHEN A.MONTH = 5 THEN 'MAY'
WHEN A.MONTH = 6 THEN 'JUNE'
WHEN A.MONTH = 7 THEN 'JULY'
WHEN A.MONTH = 8 THEN 'AUGUST'
WHEN A.MONTH = 9 THEN 'SEPTEMBER'
WHEN A.MONTH = 10 THEN 'OCTOBER'
WHEN A.MONTH = 11 THEN 'NOVEMBER'
WHEN A.MONTH = 12 THEN 'DECEMBER'
end as MONTHS
FROM
(SELECT distinct ssn,
month(recip_retir_dt) as MONTH,
year(recip_retir_dt) as YEAR ) as A
group by A.MONTHS
The query results is showing my months in alphabetical order. I want them sorted by calendar year so January would be the first.
Is there a way to do this?