Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
vc56522
Starting Member
11 Posts |
Posted - 2005-04-10 : 20:19:55
|
Hello, everyoneThis is my problem: I want to be able to group by month and yearI have a table that look lik this:date_created po_number2004-02-01 0012004-02-02 0032005-02-05 1232005-02-05 3212005-03-06 322 2005-03-07 3232005-03-08 324I want the select statement to look like this:Month Total_po_numberFeb(2004) 2Feb(2005) 2March 3This is what I have try but it is only grouping by day.SELECT DATENAME(mm,date_created) as Month, count(po_number) as Total_po_numberFROM PO_FILEGroup by DATENAME(mm,date_created),po_numberOrder by date_createdPlease help, What wrong with my code? |
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2005-04-10 : 21:24:35
|
1) SELECT does not display the Year as defined in the specification.2) GROUP BY is not grouping by Year in addition to Month as defined in the specification.3) GROUP BY is grouping by po_number which is NOT in the specification. This is why it APPEARS to be grouping by day.4) ORDER BY is using date_created instead of extracting the Month. Also, should include the Year portion.HTH=================================================================In order to improve the mind, we ought less to learn than to contemplate.-Rene Descartes, philosopher and mathematician (1596-1650) |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
|
|
|
|