sql获取分组排序后数据的脚本
程序员文章站
2023-12-03 17:01:04
先上一段代码,如下所示:复制代码 代码如下:select distinct b.orgid,b.companyid,b.areaid,b.custchannel...
先上一段代码,如下所示:
复制代码 代码如下:
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%的客户进行调查。