我已经写了这个查询,但是查询似乎很糟糕,

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和status = 5的行
并且不应该显示具有rejected_Status = 0和status = 5的行

最佳答案

这不是主要的简化,但是确实删除了与4的比较。但是,这就是我编写查询的方式:

select ga.*
from games_applied ga
where ga.games_post_id = 1126 and
      ( (ga.status not in (4, 5) and ga.rejected_status = 0) or
        (ga.status = 5 and ga.rejected_status = 1)
      );


笔记:


该表具有有意义的表别名。
所有列名称均合格。
我认为数字实际上是数字列的比较,因此我删除了单引号。
我删除了与“ 4”的比较。

10-07 19:38
查看更多