首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用未显示百分比的CASE语句

使用未显示百分比的CASE语句
EN

Stack Overflow用户
提问于 2015-02-01 12:02:33
回答 1查看 55关注 0票数 0

我有一个表,我正在尝试使用CASE语句获取百分比

代码语言:javascript
复制
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的价值是可能的吧?

我的表格看起来像这样:

代码语言:javascript
复制
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进行测试

EN

回答 1

Stack Overflow用户

发布于 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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28259325

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档