Sql Server 分组统计并合计总数及WITH ROLLUP应用

前端之家收集整理的这篇文章主要介绍了Sql Server 分组统计并合计总数及WITH ROLLUP应用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

WITH ROLLUP 在生成包含小计和合计的报表时,ROLLUP 运算符很有用。ROLLUP 运算符生成的结果集类似于 CUBE 运算符所生成的结果集。
<div class="codetitle"><a style="CURSOR: pointer" data="39889" class="copybut" id="copybut39889" onclick="doCopy('code39889')"> 代码如下:

<div class="codebody" id="code39889">
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

结果集


<div class="codetitle"><a style="CURSOR: pointer" data="31603" class="copybut" id="copybut31603" onclick="doCopy('code31603')"> 代码如下:
<div class="codebody" id="code31603">
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

原文链接:https://www.f2er.com/mssql/63638.html

猜你在找的MsSQL相关文章