表A:ID TheDate ………………
1 2008-1-1 9:00:20 ………………
2 2008-1-2 10:10:00 ………………
3 2008-2-1 11:00:40 ………………
4 2008-3-15 15:30:09 ………………………………………………………………现在想要根据TheDate,统计出每个月的记录数量,请问Sql语句怎么写???关注^^^^^
1 2008-1-1 9:00:20 ………………
2 2008-1-2 10:10:00 ………………
3 2008-2-1 11:00:40 ………………
4 2008-3-15 15:30:09 ………………………………………………………………现在想要根据TheDate,统计出每个月的记录数量,请问Sql语句怎么写???关注^^^^^
from tb
group by convert(varchar(7),TheDate,120)
select convert(varchar(7),TheDate,120) as Mth,count(*) as num
from tb
group by convert(varchar(7),TheDate,120)
from A
group by convert(char(7),thedate,120)
from tab
group by convert(varchar(7),TheDate,120)
insert @t select 1,'2008-1-1 9:00:20'
union all select 2,'2008-1-2 10:10:00'
union all select 3,'2008-2-1 11:00:40'
union all select 4,'2008-3-15 15:30:09'select convert(char(7),thedate,120),count(thedate)
from @t
group by convert(char(7),thedate,120)/*(所影响的行数为 4 行)
------- -----------
2008-01 2
2008-02 1
2008-03 1(所影响的行数为 3 行)
*/