我有下面的查詢返回銷售單位數量的銷售項目列表。銷售量最高的產品排名爲1,隨後的產品排名則按升序排列。 SELECT
RANK() OVER (ORDER BY SUM(Quantity) DESC,
SUM(LineTotalInDefaultCurrency) DESC) AS SalesRank,
P.Name ,SUM(Quantity) as Unit
我正在使用SQL Server 2008 R2。我有以下結構和樣本數據表稱爲名稱: ID Date Name DOD
10001 200911 Kevin H 06/17/2000
10001 200912 Kevin 06/20/2000
10001 201001 Kevin 06/20/2000
10001 201012 K 06/20/2000
1000
G= c("P52" ,"P52","P66 - PARK II","P66 - PARK II" ,"P66 - PARK II" ,"P66 - PARK II" ,"P82 V3","P82 V3","P82 V3","P52","P52","P66 - PARK II" ,"P66 - PARK II" ,"P82 V3","P66 - PARK II" ,"P66 - PARK II"