我无法使该查询与 SUM 函数一起使用
此查询给出错误:
select ep,
case
when ob is null and b2b_ob is null then 'a'
when ob is not null or b2b_ob is not null then 'b'
else null
end as type,
sum(b2b_d + b2b_t - b2b_i) as sales
from table
where ...
group by ep, type
错误:ORA-00904:“TYPE”:无效标识符
当我使用 group by ep
运行它时,错误消息变为:
ORA-00979:不是 GROUP BY 表达式
整个如果我删除行 sum(b2b_d+b2b_t-b2b_i) as sales
和 group by ...
,查询工作正常,所以问题应该与 SUM 和 GROUP BY 有关功能。我怎样才能做到这一点?预先感谢您的帮助。
This query gives an error:
select ep,
case
when ob is null and b2b_ob is null then 'a'
when ob is not null or b2b_ob is not null then 'b'
else null
end as type,
sum(b2b_d + b2b_t - b2b_i) as sales
from table
where ...
group by ep, type
Error: ORA-00904: "TYPE": invalid identifier
When I run it with group by ep
, the error message becomes:
ORA-00979: not a GROUP BY expression
The whole query works OK if I remove the lines sum(b2b_d+b2b_t-b2b_i) as sales
and group by ...
, so the problem should be related to SUM and GROUP BY functions. How can I make this work? Thanks in advance for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,SQL 不允许您在 GROUP BY 子句中使用列别名,因此您必须像这样重复整个 CASE:
或使用像这样的内联视图:
Unfortunately SQL doesn't allow you to use the column aliases in the GROUP BY clause, so you either have to repeat the entire CASE there like this:
or use an in-line view like this: