gpt4 book ai didi

mysql - 多个查询,其中多个有一条记录

转载 作者:行者123 更新时间:2023-11-29 10:41:37 24 4
gpt4 key购买 nike

我有一个具有许多属性的用户表。用户表具有一对多关系。我尝试选择属性表中只有一个属性的用户

select *, count(p.account_id) as c
form accounts as a
left join properties as p on a.account_id = p.account_id
group by p.account_id
having c = 1

但这似乎不起作用

最佳答案

您也可以将其作为第二个请求:

select * 
from (
SELECT *, p.account_id , count(*) as num
from accounts as a
INNER JOIN properties as p ON a.account_id = p.account_id
group by p.account_id
) query
where query.num = 1

关于mysql - 多个查询,其中多个有一条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45369358/

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