用sql语句进行多表连接查询,怎么不查出重复数据?

2024-12-03 12:19:37
推荐回答(1个)
回答(1):

SELECT T1.name,T1.buyAmount,T2.sellAmount FROM
(SELECT A.name,SUM(buyAmount) FROM A GROUP BY A.name) T1
LEFT JOIN
(SELECT B.name,SUM(sellAmount) FROM B GROUP BY B.name) T2
ON T1.name=T2.name

答案应该是这样子。先统计后联接