gpt4 book ai didi

Mysql如何通过另一个id选择最大id组,其中boolean为false

转载 作者:行者123 更新时间:2023-11-29 13:52:57 25 4
gpt4 key购买 nike

我有下表:

  • 主要 Int ID
  • 整数 another_id
  • bool 条件

我想选择由 another_id 分组的所有 max(id),但前提是 max(id) 行的条件等于 FALSE.

我尝试SELECT MAX(id) WHERE条件IS FALSE GROUP BY another_id,但我得到了以前的id。例如,如下表:

 id | another_id | condition
1 | 42 | 0
2 | 42 | 1
3 | 31 | 0
4 | 77 | 1

我想要的唯一结果是id == 3

有什么办法可以做到这一点吗?

提前谢谢您!

最佳答案

SELECT
MAX(id)
FROM
Table1 t
GROUP BY another_id
HAVING SUM(`condition`) = 0

sqlfiddle 中观看直播.

关于Mysql如何通过另一个id选择最大id组,其中boolean为false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16397939/

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