mysql 使用求和函数更新表时组函数的使用无效

vx6bjr1n  于 2023-03-11  发布在  Mysql
关注(0)|答案(2)|浏览(125)

我有两张table:o_daily_lcsgenerationo_daily_generation
尝试更新o_daily_generation时,我收到错误消息:

error(1111) invalid use of Group function

下面是我正在运行的代码:

update o_daily_generation join o_daily_lcsgeneration 
on o_daily_generation.Location =o_daily_lcsgeneration.Location 
   and o_daily_generation.Date =o_daily_lcsgeneration.Date  
set o_daily_lcsgeneration.Turbine_Generation =sum(o_daily_generation.Turbine_Generation)
f8rj6qna

f8rj6qna1#

试试这个:

UPDATE o_daily_generation od
INNER JOIN 
(
     SELECT Location, SUM(Turbine_Generation) TurbineSum
     FROM o_daily_lcsgeneration
     GROUP BY Location
) og ON od.Location = og.Location
SET od.Turbine_Generation = og.TurbineSum
j9per5c4

j9per5c42#

我确实根据上述回答更新了上述查询,但有一个问题。

UPDATE tmpTotal t1
    INNER JOIN 
    (
         SELECT thirdlevel_delivery_id, MAX(baseline_id) MaxBaseLineId
         FROM tmpTotal
         GROUP BY release_id
    ) t2 ON t1.release_id = t2.release_id
    SET t1.planned_delivery_date = t2.MaxBaseLineId;

它提供了

Error Code : 1054
Unknown column 't2.release_id' in 'on clause'

相关问题