数据库教程:Sql Server 分组统计并合计总数及WITH ROLLUP应用

with rollup 在生成包含小计和合计的报表时,rollup 运算符很有用。rollup 运算符生成的结果集类似于 cube 运算符所生成的结果集。 复制代码 代码如

with rollup 在生成包含小计和合计的报表时,rollup 运算符很有用。rollup 运算符生成的结果集类似于 cube 运算符所生成的结果集。

复制代码 代码如下:
select [source], count(*) as ordertotal from [externalorder] where orderstatus=1 and (checkpayment=1 ) and ticketdate >= ‘2012-11-1’ and ticketdate < ‘2012-12-1’ group by [source] with rollup order by [source] desc

结果集

复制代码 代码如下:
source ordertotal
zonghengv2 215
zongheng 3889
yixingsky 3919
yiskyv2 901
wanggou 1034
uni800 1151
taobao 3876
shanglvpt 897
shanglvbao 426
qunar 9878
piaomeng 429
kuxun 1549
jinri 2661
hangtuo 140
hanglvtong 7
easygo 501
aooxing 5458
airpp 3299
yi 8677
book 2401
19479
null 70787

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/dtteaching/616984.html

(0)
上一篇 2021年5月20日
下一篇 2021年5月20日

精彩推荐