在内部查询中引用外部查询(UPDATE)列会在MySQL上出错

时间:2023-01-03 00:15:45

I have a query like the following :

我有如下查询:

UPDATE prog_fatt
SET    fat_prg = (SELECT MAX(VALUE)
                  FROM   (SELECT 0 AS VALUE
                          UNION
                          SELECT fat_prg - 1 AS VALUE) AS T1) 

that works on SQL Server, but gives :

适用于SQL Server,但给出:

ERROR 1054 (42S22): Unknown column 'fat_prg' in 'field list'

error on MySQL, is there a way to make it works under MySQL ?

关于MySQL的错误,有没有办法让它在MySQL下工作?

1 个解决方案

#1


2  

That is not valid in MySQL but you don't need it here

这在MySQL中无效,但你不需要它

UPDATE prog_fatt
SET    fat_prg = greatest(fat_prg - 1, 0) 

should work.

#1


2  

That is not valid in MySQL but you don't need it here

这在MySQL中无效,但你不需要它

UPDATE prog_fatt
SET    fat_prg = greatest(fat_prg - 1, 0) 

should work.