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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-06-10 : 09:26:15
|
| Tim writes "I'm trying to make a query that will list the 12 months and the total number of applications for each month from a table that has lists hundreds of applications and include the date for each. I can extract the months, and I can find totals with a COUNT query for each month individually, but is there a way I can make it one query and avoid joining tables? I've tried doing stuff like:SELECT DISTINCT MONTH(APP_DATE) AS MONTH,COUNT(*) FROM APPS WHERE MONTH(APP_DATE) = MONTH AS NUM_APPSFROM APPSOf course, that's not working... Thanks for any help!" |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2002-06-10 : 09:40:50
|
take a look at group by . . .select month(app_date) as month, count(*)from appsgroup by month(app_date) ...you should note that this will group jan 2000 with jan 2001 with jan 2002 as you are only grouping by month not month/year...<O> |
 |
|
|
sqltimmy
Starting Member
1 Post |
Posted - 2002-06-10 : 10:50:32
|
| Thanks! That was exactly what I was looking for. One thing now - when I use GROUP BY, I always receive my groupings in reverse order. For instance, when I group by the month, The rows will come in the order: 12, 11, ..., 2, 1. Is there a way I can reverse that order? Thanks again! |
 |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2002-06-10 : 10:55:25
|
| prepare to smack yourself in the forehead . . . .ORDER BY month(app_date) ASCENDING<O> |
 |
|
|
|
|
|