SQL gets the script _mssql of the sorted data after grouping

Source: Internet
Author: User

First the previous code, as follows:

Copy Code code as follows:

SELECT DISTINCT
B.orgid,b.companyid,b.areaid,b.custchannelid,b.custid,b.saletotalqty,
GETDATE () from kds400telsurveycustall_temp as Tmp1 cross apply
(
Select top percent * from Kds400telsurveycustall_temp TMP2
where Tmp1.orgid=tmp2.orgid and Tmp1.companyid=tmp2.companyid
and TMP1. Areaid=tmp2. Areaid and TMP1. Custchannelid=tmp2. Custchannelid
and TMP2. Custchannelid in (1027,1028)
ORDER BY Tmp2.orgid,tmp2.companyid,tmp2.areaid,tmp2.areatype,tmp2.custchannelid
) as B

This code means to get each distributor in each county city in two categories of customers
Take the first 3 months of the total number of customers in the top 10% customers to investigate.

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.