gpt4 book ai didi

Mysql连接两个表

转载 作者:行者123 更新时间:2023-11-29 08:59:33 25 4
gpt4 key购买 nike

我需要连接以下两个表

table_A
id userId name score game
1 2343 me 45 Palo Alto
2 6575 other 21 SF
3 6575 other 2 miami

table_B
id userId pen mango
1 2343 3 4
2 2343 5 7
3 6575 1 2

这是连接:

SELECT COUNT(a.userId), SUM(b.pen), SUM(b.mango) 
FROM table_A AS a
LEFT JOIN table_B b ON a.userId = b.userId
WHERE userId = 2343;

问题是我得到的 count(userId) 等于 2,但我需要它为 1。我做错了什么?

最佳答案

将其更改为以下内容:

count(distinct a.userId)

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

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