gpt4 book ai didi

mysql - 选择在其他表中有不止一次经验的用户

转载 作者:行者123 更新时间:2023-11-29 00:14:30 25 4
gpt4 key购买 nike

tblusers:

+-------------+---------------+----------+
| id_users | user | password |
+-------------+---------------+----------+
| 1 | gurodrigues | 1234 |
| 2 | lower52 | 123 |
| 3 | test55 | 1234 |
+-------------+---------------+----------+

tblexperiences:

+----------------+-----------+-------------------+
| id_experience | id_users | detail |
+----------------+-----------+-------------------+
| 1 | 1 | 'Cool, fantastic' |
| 2 | 1 | 'Nice!!' |
| 3 | 2 | 'Boring' |
+----------------+-----------+-------------------+

SELECT tblusers.id, tblusers.user from tblusers, tblexperiences WHERE tblexperiences.id = tblusers.id

如果我先执行此操作,SELECT 会返回很多重复的行,但我只需要一次,我该怎么做?

在另一个 SELECT 中,我必须让所有用户都在 tblexperiences WHERE 有不止一行 tblexperiences.id_users

最佳答案

SELECT tblusers.id, tblusers.user 
from tblusers
join tblexperiences ON tblexperiences.id = tblusers.id
group by tblusers.id, tblusers.user

对于问题的第二部分,添加一个

having count(tblexperiences.id) > 1

关于mysql - 选择在其他表中有不止一次经验的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23476661/

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