Heim  >  Artikel  >  Datenbank  >  SQL中获取排序分组后数据的脚本

SQL中获取排序分组后数据的脚本

WBOY
WBOYOriginal
2016-06-07 16:19:21992Durchsuche

废话不多说了,先上一段代码,如下所示: 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 KDS400TelSurveyCustA

   废话不多说了,,先上一段代码,如下所示:

  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%的客户进行调查。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn