首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求一条分页后小计的查询语句(待)

2012-01-11 
求一条分页后小计的查询语句(在线等待)表A:moneydate100.0007年6月150.0007年7月100.0007年8月150.0007年9

求一条分页后小计的查询语句(在线等待)
表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)

热点排行