SQL Server grouping statistics and total count and applications with Rollup

Source: Internet
Author: User

The with rollup operator is useful when generating reports that contain subtotal and aggregate. The result set generated by the rollup operator is similar to the result set generated by the cube operator. CopyCodeThe Code is as follows: select [Source], count (*) as ordertotal from [externalorder] Where orderstatus = 1 and (checkpayment = 1) and ticketdate> = '2014-11-1 'and ticketdate <'2014-12-1' group by [Source] With rollup order by [Source] DESC

Result set:Copy codeThe Code is as follows: Source ordertotal
Zonghengv2 215
Zongheng 3889
Yixingsky3919
Yiskyv2 901
Wanggou 1034
Uni800 1151
Taobao 3876
Sh anglvpt 897
Shanglvbao 426
Qunar 9878
Piaomeng 429
Kuxun 1, 1549
Jinri 2661
Hangtuo 140
Hanglvtong 7
Easygo 1, 501
Aooxing 5458
Airpp 3299
Yi 8677
Book 2401
19479
Null 70787

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.