您好想知道如何使用PostgreSQL求和()“CALL ID count”,然后将结果放在列表的底部。我试过工会和小组。
AGENT CALL ID count
xxxxx 13
xxxxx 21
xxxxx 49
xxxxx 58
xxxxx 67
xxxxx 32
xxxxx 9
xxxxx 8
xxxxx 39
xxxxx 1047
说
AGENT CALL ID count
xxxxx 13
xxxxx 21
xxxxx 49
xxxxx 58
xxxxx 67
xxxxx 32
xxxxx 9
xxxxx 8
xxxxx 39
xxxxx 1047
TOTAL 1343
Select Agent,Sum("CALL ID count") as TOTAL
from AgentCount
group by "CALL ID count"
order by Agent
我希望得到代理商的名称,然后计算最终的总数 谢谢
答案 0 :(得分:1)
您必须使用UNION合并两个查询,然后相应地使用ORDER BY,请看下面的示例:
Select Agent,Sum("CALL ID count") as TOTAL
from AgentCount
group by Agent
UNION
Select 'TOTAL' AS Agent ,Sum("CALL ID count") as TOTAL FROM AgentCount
ORDER BY CASE WHEN Agent = 'TOTAL' THEN 1 ELSE 0 END ASC, Agent