gpt4 book ai didi

mysql - 使用mysql连接两个子查询语法错误

转载 作者:行者123 更新时间:2023-11-29 18:01:19 25 4
gpt4 key购买 nike

我在 sql 中使用以下代码,它给了我语法错误。谁能帮我找出原因吗?谢谢!

(
select accepter_id, count(*) as accept_cnt
from request_accepted
group by accepter_id) a
left join
(
select requester_id, count(*) as request_cnt
from request_accepted
group by requester_id) b
on a.accepter_id = b.requester_id

最佳答案

如果没有 request_accepted 的定义,这有点困难,但这是我给你的试用:

select a.accepter_id, 
(SELECT COUNT(*) FROM request_accepted ac WHERE ac.accepter_id = a.accepter_id) AS accept_cnt,
b.requester_id,
(SELECT COUNT(*) FROM request_accepted bc WHERE bc.requester_id = b.requester_id) AS request_cnt
from request_accepted a
left join request_accepted b
on a.accepter_id = b.requester_id
GROUP BY a.accepter_id, b.requester_id

关于mysql - 使用mysql连接两个子查询语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48305762/

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