문제

I need to do an update query where I'm setting a value based on results from a count query. If the count returns no results, I want to set the status to 1, otherwise i want to set the status to 2.

Here's my attempt which doesn't work:

UPDATE TABLE_1 SET status = ((select count(1) from TABLE_2) > 0 ? 1 : 2)

Also, I'm doing this within a mybatis xml file, so if there is some magic I can do in mybatis that would work too.

도움이 되었습니까?

해결책

Hope DECODE Helps you! But all the rows in Status updated with same value.. You want it that way ?

UPDATE TABLE_1 SET status = (select DECODE(count(1),0,2,1) from TABLE_2);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top