我正在尝试将两个表链接在一起,以便我可以从中获取以下数据。但我得到的只是第一个人的所有总数,而没有给其他人。 它看起来应该如下所示
pid firstname nid Total
18 Teresa 3 65846.50
18 Richard 1 3005.00
18 Camdon 7 2000.00
加入有效但总和无法正常工作
SELECT
notarys.pid,
notarys.firstname,
notarys.nid,
SUM(
signings.samount+
signings.prtamount+
signings.faxamount
)AS Total
FROM
notarys
INNER JOIN signings ON notarys.nid = signings.nid
WHERE
signings.pid = signings.pid
AND signings.done = 1
ORDER BY
notarys.nid ASC
答案 0 :(得分:0)
需要GROUP BY
。
SELECT
notarys.pid,
notarys.firstname,
notarys.nid,
SUM(
signings.samount+
signings.prtamount+
signings.faxamount
)AS Total
FROM
notarys
INNER JOIN signings ON notarys.nid = signings.nid
WHERE
signings.pid = signings.pid
AND signings.done = 1
GROUP BY notarys.nid, notarys.pid
ORDER BY notarys.nid ASC