我想检查表 table1 中 sno = 5 的记录数。
我所需要的只是一个 bool 值 true 或 false。
怎么做?
我能做到
select count(*) from table1 where sno = 5
然后检查返回值是否等于5。
我想要这样的东西:
select 1 (else 0) where (select count(*) from table1 ) = 5;
感谢您的帮助。
最佳答案
select IF(count(*)=5, 1, 0) as has_5_items from table1 where sno = 5;
关于mysql - 需要帮助构建 mysql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8801691/