日期:2014-05-18  浏览次数:20367 次

求一条分页后小计的查询语句(在线等待)
表A:
money     date
100.00   07年6月
150.00   07年7月
100.00   07年8月
150.00   07年9月
100.00   07年10月
150.00   07年11月

这个是我分页后的结果。分页代码如下:
select   top   20   from   (select   sum(money)as   money,Convert(varchar(4),year(date),120)+ '- '+Convert(varchar(4),month(date),120)as   date   from   a   group   by   Convert(varchar(4),year(date),120)+ '- '+Convert(varchar(4),month(date),120)   order   by   date   asc)   as   tmptable_1
order   by   date   desc

如何修改这个SQL语句可以达到如下效果:
money     date
100.00   07年6月
150.00   07年7月
100.00   07年8月
150.00   07年9月
100.00   07年10月
150.00   07年11月
750.00     null

------解决方案--------------------
750.00 null
程序设计端统计即可,而且又简单,没有必要放到存储过程中。
------解决方案--------------------
select sum(money) ,[date] from (
select top 20 money, [date] from (select sum(money)as money,Convert(varchar(4),year(date),120)+ '- '+Convert(varchar(4),month(date),120)as date from a group by Convert(varchar(4),year(date),120)+ '- '+Convert(varchar(4),month(date),120) order by date asc) as tmptable_1
order by date desc)
group by [date] with rollup
------解决方案--------------------
select * from A
union all
select money = sum(money) from A group by Convert(varchar(4),year(date),120)