我已经编写了这个查询,但它似乎是一个非常糟糕的查询,
select * from games_applied where
games_post_id='1126' and status != '4' and
(status != '5' and rejected_status = '0' or status = '5' and rejected_status = '1');
如何更好地利用这种情况。
(status != '5' and rejected_status = '0' or status = '5' and rejected_status = '1')
应仅显示 rejected_status = 1且状态= 5 的行 并且不应显示 rejected_Status = 0且状态= 5
的行答案 0 :(得分:1)
这不是一个主要的简化,但确实删除了与Dense
的比较。但是,这就是我编写查询的方式:
4
注意:
答案 1 :(得分:1)
您的查询所需的唯一改进是将两个子句封装在或语句的任一侧。换句话说,将status
和rejected_status
检查放在括号内。
select
*
from
games_applied
where
games_post_id='1126'
and status != '4'
and
(
(status != '5' and rejected_status = '0')
or (status = '5' and rejected_status = '1')
);
答案 2 :(得分:0)
以下是查询,希望它可以按要求运行:
select * from games_applied where
games_post_id='1126' and status != '4' and case when status='5' then
rejected_status='1' else rejected_status='0' end;