gpt4 book ai didi

mysql - 如何根据and条件获取数据

转载 作者:行者123 更新时间:2023-11-29 09:49:38 24 4
gpt4 key购买 nike

我正在尝试获取所有值等于 hello & world 的 ID。既然我有这个数据结构,我怎样才能得到这个数据?

id value
1 hello
1 world
2 hai
3 hello
3 world

预期输出

id
1
3

最佳答案

你需要一个 self joinid检查是否有相同 id 的记录有helloworldvalue专栏。

以下查询将为您提供所需的输出。

select t1.id 
from @table t1
inner join @table t2
on t1.id = t2.id
where t1.value = 'hello'
and t2.value = 'world'

Online Demo

输出

+----+
| id |
+----+
| 1 |
+----+
| 3 |
+----+

关于mysql - 如何根据and条件获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55034074/

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