Sql Server 分組統計並算計總數及WITH ROLLUP運用。本站提示廣大學習愛好者:(Sql Server 分組統計並算計總數及WITH ROLLUP運用)文章只能為提供參考,不一定能成為您想要的結果。以下是Sql Server 分組統計並算計總數及WITH ROLLUP運用正文
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