php – 如何检查所有行是否具有相同的列值?
发布时间:2020-12-13 21:55:06 所属栏目:PHP教程 来源:网络整理
导读:这是简单的查询: SELECT status FROM tbl_pedidos_produtos WHERE status = 4; 显然,这只给我带来状态等于4的条目,但是这样我就无法测试所有条目是否都有状态4.我怎么能这样做? SELECT status FROM tbl_pedidos_produtos WHERE status OF ALL = 4; 解决方
这是简单的查询:
SELECT status FROM tbl_pedidos_produtos WHERE status = 4; 显然,这只给我带来状态等于4的条目,但是这样我就无法测试所有条目是否都有状态4.我怎么能这样做? SELECT status FROM tbl_pedidos_produtos WHERE status OF ALL = 4; 解决方法
您可以使用聚合执行此操作.这是一种方式:
select (max(status) = 4 and min(status) = 4 and status is not null) as AllSameFlag from tbl_pedidos_produtos; 另一种可能不太明显的方式: select (count(*) = 0) as AllSameFlag from tbl_pedidos_produtos where status <> 4 or status is null (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |