gpt4 book ai didi

mysql - 按 bool 列标志选择记录

转载 作者:行者123 更新时间:2023-12-01 00:34:57 25 4
gpt4 key购买 nike

我有一张这样的表:

+----+--------------+-----------+------------+
| id | natural_id | flag | date |
+----+--------------+-----------+------------+
| 1 | 1 | true | 01/01/2000 |
| 2 | 1 | true | 02/01/2000 |
| 3 | 1 | false | 03/01/2000 |
| 3 | 2 | true | 01/01/2000 |
| 4 | 2 | false | 02/01/2000 |
| 5 | 2 | false | 03/01/2000 |
+----+--------------+-----------+------------+

我正在尝试编写 select,它将根据 first flag< 显示具有 natural_iddate 的记录/strong> 错误值:

+--------------+------------+
| natural_id | date |
+--------------+------------+
| 1 | 03/01/2000|
| 2 | 02/01/2000|
+---------------------------+

我不知道如何在 SQL 中执行此操作。在纯 SQL 中甚至可能吗?

最佳答案

按 natural_id 分组:

select 
natural_id,
min(date) date
from tablename
where flag = 'false'
group by natural_id

如果标志的类型是BOOLEAN,你可以这样做:

select 
natural_id,
min(date) date
from tablename
where not flag
group by natural_id

关于mysql - 按 bool 列标志选择记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55405233/

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