我有一个表,我正在尝试使用CASE语句获取百分比
SELECT "Agent",
(100* ( max(case when "Agent"= 'Agent1' then "TOTAL" end)/
max(case when "Agent" = 'TOTAL' then "TOTAL" end) ))
as "Agent1%"
From "SumofAgent"
group by Agent查询在新列旁边显示一个空白。我在想这可能是因为small..is的价值是可能的吧?
我的表格看起来像这样:
Agent TOTAL
----- -----
Agent1 13
Agent2 21
Agent3 49
TOTAL 1343(13/1343)*100=0.96%
我已经尝试了他们自己的max(case when "Agent" = 'TOTAL' then "TOTAL" end)和max(case when "Agent"= 'Agent1' then "TOTAL" end)的案例陈述。它们提取了正确的值,但当您尝试计算时,它不会显示任何内容。
使用Zoho报告,但将使用PostgreSQL进行测试
发布于 2015-02-01 13:36:40
在组'Agent1‘中,max(case when "Agent" = 'TOTAL' then "TOTAL" end)为null
和组‘max(case when "Agent"= 'Agent1' then "TOTAL" end)’中的合计为空
所有其他组都为空。
因此,结果列中的每个值在所有结果行上都为null。
请看这里的示例:
How to use a SQL window function to calculate a percentage of an aggregate
https://stackoverflow.com/questions/28259325
复制相似问题