根据客户分组商品销售前3名
SELECT * FROM ( SELECT vl.DM1 AS 客户代码, k.KHMC AS 客户名称, vl.SPDM AS 商品代码, s.SPMC AS 商品名称, CAST(SUM(SL) AS INT) AS 销售数量, DENSE_RANK()OVER(PARTITION BY vl.dm1 ORDER BY SUM(SL) DESC) AS 名次 FROM VW_LSXHDMX AS vl LEFT JOIN KEHU AS k ON k.KHDM = vl.DM1 LEFT JOIN SHANGPIN AS s ON s.SPDM = vl.SPDM GROUP BY vl.dm1 , vl.SPDM , k.KHMC , s.SPMC ) T1 WHERE t1.[名次] <= 3 ORDER BY t1.[客户代码] , T1.[名次]
本文来自博客园,作者:liessay,转载请注明原文链接:https://www.cnblogs.com/liessay/p/8056019.html