SQL script for retrieving data After grouping and sorting

Source: Internet
Author: User

First, the Code is as follows:
Copy codeThe Code is 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 10 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 is used to obtain two types of customers from each dealer in each county-level city.
The top 10% customers with the cumulative sales volume in the first three months of various customers were investigated.

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.