先上一段代碼,如下所示:
復制代碼 代碼如下:
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
這段代碼的意思是獲取取每個經銷商在每個縣級城市中兩類客戶
取各類客戶的前3個月累計銷量排名在前10%的客戶進行調查。