部门 分部门 销售金额
A XY 15678
B ZY 12400
A TT 11232
C OP 10089
B TX 9879
C TL 5678
我按销售金额排序,可是出现的是按照各个分部门的销售金额排序的.
如果我想按照整个部门销售金额排序,比如整个A部门的两个分部门的总计是最高的,整个A部门排第一,再按分部门的销售金额由高到低排序,于是整个A部门的两个分部门就分列第一,第二,依此类推...
部门 分部门 销售金额
A XY 15678
A TT 11232
B ZY 12400
B TX 9879
C OP 10089
C TL 5678
SELECT A1.*
FROM TTPO AS A1 LEFT JOIN [SELECT 部门,
(SELECT COUNT(*) FROM
(SELECT 部门,SUM([销售金额]) AS MA1
FROM TTPO
GROUP BY 部门) A
WHERE MA1>=MA
) AS PX
FROM (
SELECT 部门,SUM([销售金额]) AS MA
FROM TTPO
GROUP BY 部门)
]. AS D ON A1.部门=D.部门
ORDER BY PX, 销售金额 DESC;
ACCESS加了方括号,去掉:
SELECT A1.*
FROM TTPO AS A1 LEFT JOIN (SELECT 部门,
(SELECT COUNT(*) FROM
(SELECT 部门,SUM([销售金额]) AS MA1
FROM TTPO
GROUP BY 部门) A
WHERE MA1>=MA
) AS PX
FROM (
SELECT 部门,SUM([销售金额]) AS MA
FROM TTPO
GROUP BY 部门)
) AS D ON A1.部门=D.部门
ORDER BY PX, 销售金额 DESC;