如何在case语句中使用条件:
select * from tbl
where case when expr then
(
(x=@_megacity and state_group in (select * from temp_state_megacity)) OR
(x=@_10lac and state_group in (select * from temp_state_10lac)) OR
(x=@_below10 and state_group in (select * from temp_state_below10)) OR
(x=@_rural and state_group in (select * from temp_state_rural))
) else true end
错误 - 语法错误
答案 0 :(得分:2)
在WHERE
子句中,您使用AND
,OR
和NOT
来组合表达式:
select * from tbl
where NOT <expression> OR
(
(x=@_megacity and state_group in (select * from temp_state_megacity)) OR
(x=@_10lac and state_group in (select * from temp_state_10lac)) OR
(x=@_below10 and state_group in (select * from temp_state_below10)) OR
(x=@_rural and state_group in (select * from temp_state_rural))
);