gpt4 book ai didi

mysql - SQL 条件分组依据

转载 作者:搜寻专家 更新时间:2023-10-30 20:03:45 24 4
gpt4 key购买 nike

给定这张表

id_order|id_status|
--------|---------|
141 |4 |
141 |4 |
142 |4 |
142 |4 |
143 |5 |
143 |4 |

我想执行一个查询来提取所有 id_status 都等于 4 的 id_orders,所以在这种情况下,输出应该是:

id_order
--------
141
142

id_order 为 143 的订单将被排除,因为它有一行 id_status <> 4。

最佳答案

我只会使用group byhaving:

select id_order
from t
group by id_order
having min(id_status) = max(id_status) and min(id_status) = 4;

关于mysql - SQL 条件分组依据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53673185/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com