8

私は2つのテーブルを持っています: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)
4

2 に答える 2

11

代わりにこれを試してください:

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
于 2012-11-03T07:44:02.413 に答える
2

上記の回答に基づいて上記のクエリを更新しましたが、問題があります。

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'
于 2013-11-12T15:51:30.980 に答える