gpt4 book ai didi

mysql - 如何选择所有行都具有的行的 ID

转载 作者:太空宇宙 更新时间:2023-11-03 11:22:47 24 4
gpt4 key购买 nike

有一张 table :

+-------------+----------+
|stud_group_id|subject_id|
+-------------+----------+
| 1g | 1s |
+-------------+----------+
| 1g | 2s |
+-------------+----------+
| 1g | 3s |
+-------------+----------+
| 2g | 1s |
+-------------+----------+
| 2g | 2s |
+-------------+----------+
| 3g | 1s |
+-------------+----------+
| 3g | 2s |
+-------------+----------+
| 3g | 4s |
+-------------+----------+

我需要选择所有 stud_group_id 学习的 subject_id。我期待

+----------+
|subject_id|
+----------+
| 1s |
+----------+
| 2s |
+----------+

我该怎么做?谢谢

最佳答案

试试这个:

select 
subject_id,
count(distinct stud_group_id) as cnt
from
<your_table>
group by
subject_id
having cnt=(select count(distinct stud_group_id) from <your table>)

关于mysql - 如何选择所有行都具有的行的 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57852031/

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