create table test
(
订单号 varchar(7),
品名 varchar(5),
金额 int
)insert into test select 'P061001', 'End1', 180
insert into test select 'P061001', 'END2', 260
insert into test select 'P061001', 'END3', 330
insert into test select 'P061200', 'PON1', 150
insert into test select 'P061200', 'PON2', 510
insert into test select 'P061200', 'PON3', 150select case when GROUPING(订单号) = 1 then '总计' when 品名 is null then '小计' else 订单号 end as 订单号,
isnull(品名,'') as 品名,sum(金额) as 金额
from test
group by 订单号,品名 with ROLLUP P061001 End1 180
P061001 END2 260
P061001 END3 330
小计 770
P061200 PON1 150
P061200 PON2 510
P061200 PON3 150
小计 810
总计 1580
解决方案 »
- 怎么跟踪数据库做了哪些改变?
- 寻找最优解决方案,合并查询
- 在用代理服务器上网的客户端,怎么连接服务器的数据库,怎么配置
- 在T-SQL中只有while一种循环么?
- 为何页面显示正常,但数据库里是乱码?
- 高手请进,为什么我的SQL-SERVER的各项操作均特别慢?
- 数据库结构模型问题!!
- 一个GUID字段(sql server2000)可以手动添加值么? 即在INSERT时加入自己生成的值(可通过API函数实现) HRESULT hr = ::UuidCreate(&m_gu
- 在存儲過程中已做錯誤處理,為什麼還會將過程中的錯誤返回給前端程式?
- SQL语句如何写?
- 急,在线等候
- SQL Server备份问题
union all
select 小计 as 订单号,品名='',金额=sum(金额) from tablename where 订单号='P061001'
union all
select * from tablename where 订单号='P061002'
union all
select 小计 as 订单号,品名='',金额=sum(金额) from tablename where 订单号='P061002'
union all
select 总计 as 订单号,品名='',金额=sum(金额) from tablename
union
select ddh+'小计','',sum(je) from test_pp
group by ddh
union
select '总计','',sum(je) from test_pp