gpt4 book ai didi

sql - 使用ORA-00904的SQL有什么问题?

转载 作者:行者123 更新时间:2023-12-02 09:26:29 24 4
gpt4 key购买 nike

我的sql有什么问题?我在sybase中工作得很好,但是在oracle中工作不正确。

    select Col1 as bus_type,
count(*) as cnt,
sum(count(*)) as sums
from t_form_25
where Node_value ='6'
group by bus_type
order by cnt desc

它显示:

[Err] ORA-00904: "BUS_TYPE": invalid identifier



如何解决?它在sybase中效果很好。

最佳答案

您的代码中有两个错误!

  • 您不能在GROUP BY子句中引用与创建别名相同级别的别名。
  • 您不能在同一级别的聚合函数上执行聚合函数!同样,如果要使用它,则必须用另一个选择包装它。

  • 所以:
    SELECT bus_type,cnt,sum(cnt) OVER(ORDER BY 1) sum_cnt
    FROM (
    select Col1 as bus_type,
    count(*) as cnt
    from t_form_25
    where Node_value ='6'
    group by Col1)
    GROUP BY bus_type,cnt
    order by cnt desc

    我不完全了解您在此处尝试执行的操作,也许您将不得不省略其中一列,因为现在总和始终等于 cnt

    关于sql - 使用ORA-00904的SQL有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37569715/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com