Current Status

Actively playing with all possible backend services

15 December, 2010

sql Query to Group By Year, Month, Week, Day

I tried to make a report to see a list of total records, grouped by month:


Which i found from articles:

SELECT Sum(someValues) 
FROM Table 
GROUP BY Year(date_feild), Month(date_feild), Day(date_feild) 


what i wrote first:

select count(*),Year(entered_on) ,Month(entered_on)
 from receipt_table
group by 2,3


I end up with:

select Year(entered_on) as Year,Month(entered_on) as Month,count(*)
 from receipt_table
group by 1,2
order by 1,2


any comments guys?

Some Popular Posts