gpt4 book ai didi

sql - Mysql SQL连接问题

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

我正在尝试查找所有交易信息以及他们收到的评论数量。我的查询

select deals.*,
count(comments.comments_id) as counts
from deals
left join comments on comments.deal_id=deals.deal_id
where cancelled='N'

但现在它只显示至少有一条评论的交易。有什么问题吗?

最佳答案

您错过了 GROUP BY

select deals.*, count(comments.comments_id) as counts 
from deals
left join comments on comments.deal_id=deals.deal_id
where cancelled='N'
GROUP BY deals.deal_id

关于sql - Mysql SQL连接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3001092/

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