gpt4 book ai didi

mysql - 如何求和两个字段

转载 作者:太空宇宙 更新时间:2023-11-03 11:34:08 25 4
gpt4 key购买 nike

我正在尝试执行算术运算符,这是我的查询,

SELECT

GLB.BEGIN_BALANCE_DR_BEQ + GLB.BEGIN_BALANCE_CR_BEQ AS ACTIVITY,
GLB.PERIOD_NET_DR + GLB.PERIOD_NET_CR AS BEG_BALANCE ,
ACTIVITY + BEG_BALANCE AS END_BALANCE,
SUM(ACTIVITY) AS TOTAL_ACT,
SUM(BEG_BALANCE) AS TOTAL_BEG_BALANCE,
SUM(END_BALANCE) AS TOTAL_END_BALANCE,

但它没有用,任何人都可以指导我如何修复它?!

最佳答案

在你的情况下,你不能在相同的选择级别使用别名(并且你不能使用聚合级别而不是没有适当分组依据的聚合列)

您应该使用子查询来快速使用别名,例如:

  SELECT 
SUM(ACTIVITY) AS TOTAL_ACT,
SUM(BEG_BALANCE) AS TOTAL_BEG_BALANCE,
SUM(END_BALANCE) AS TOTAL_END_BALANCE
FROM(
SELECT

GLB.BEGIN_BALANCE_DR_BEQ + GLB.BEGIN_BALANCE_CR_BEQ AS ACTIVITY,
GLB.PERIOD_NET_DR + GLB.PERIOD_NET_CR AS BEG_BALANCE ,
ACTIVITY + BEG_BALANCE AS END_BALANCE
FROM My_TABLE
) T

关于mysql - 如何求和两个字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47337981/

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