使用CASE WHEN 做条件的筛选,但是一直报错;
select
*
from
pnassertchuku_middle (
case when #{identification} =='2' and (select identification = '1' from pnassertchuku_middle where child_pnAssertChuKuDetails_id = #{childPnAssertChuKuDetailsId})
then
update
pnassertchuku_middle
set
identification = '2'
where
child_pnAssertChuKuDetails_id = #{childPnAssertChuKuDetailsId}
else end as identification case when #{identification} =='0' and (select identification = '1' from pnassertchuku_middle where child_pnAssertChuKuDetails_id = #{childPnAssertChuKuDetailsId})
then
update
pnassertchuku_middle
set
identification = '0'
where
child_pnAssertChuKuDetails_id = #{childPnAssertChuKuDetailsId}
else end as identification
)
where
child_pnAssertChuKuDetails_id = #{childPnAssertChuKuDetailsId}
报错:
### Error updating database. Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '( case when '0' =='2' and (select identification = '1' f' at line 1 ### The error may exist in file [D:\mes-master\mes-master\ruoyi-system\target\classes\mapper\system\pnChuKuMapper.xml] ### The error may involve com.ruoyi.system.mapper.PnChuKuMapper.updatePnassertchukuMiddle-Inline ### The error occurred while setting parameters ### SQL: select * from pnassertchuku_middle ( case when ? =='2' and (select identification = '1' from pnassertchuku_middle where child_pnAssertChuKuDetails_id = ?) then update pnassertchuku_middle set identification = '2' where child_pnAssertChuKuDetails_id = ? else end as identification case when ? =='0' and (select identification = '1' from pnassertchuku_middle where child_pnAssertChuKuDetails_id = ?) then update pnassertchuku_middle set identification = '0' where child_pnAssertChuKuDetails_id = ? else end as identification ) where child_pnAssertChuKuDetails_id = ? ### Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '( case when '0' =='2' and (select identification = '1' f' at line 1 ; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '( case when '0' =='2' and (select identification = '1' f' at line 1
不能在一个SELECT语句里套UPDATE语句