比如说,我想查出,这三个月内发出来的新文章,并且把总的记录数,也一次查出来Articla
ID Title Date
1 a jun
2 b jul
3 c feb
4 d aug
5 e mar表到结果(当前月8月)
最新文章(条)
a jun
b jul
d aug谢谢
ID Title Date
1 a jun
2 b jul
3 c feb
4 d aug
5 e mar表到结果(当前月8月)
最新文章(条)
a jun
b jul
d aug谢谢
(ID int, Title varchar(10), Date varchar(10))
insert into #t
select 1, 'a', 'jun' union all
select 2, 'b', 'jul' union all
select 3, 'c', 'feb' union all
select 4, 'd', 'aug' union all
select 5, 'e', 'mar'select id,當前月=date,count(*)as count from #t where date
in(left(dateadd(month,-2,getdate()),3),left(dateadd(month,-1,getdate()),3),left(getdate(),3))
group by id,dateid 當前月 count
----------- ---------- -----------
4 aug 1
2 jul 1
1 jun 1(3 row(s) affected)