這裏我將cr.credit
值作爲相同值的倍數。但我需要確切的價值來計算總價值。任何人都可以幫助我得到答案。在sql中總結多個列總計
SELECT
gm.id,
gm.groupid,
gm.tktno,
gm.memberid,
(COALESCE((g.emdue - ae.dividend), 0)) AS a,
SUM(ra.debit) AS deb,
SUM(DISTINCT ra.credit) AS cr,
COALESCE((SUM(ra.debit) - SUM(ra.credit)), 0) AS b,
COALESCE(SUM(cr.credit_value), 0) AS c,
COALESCE((COALESCE((g.emdue - ae.dividend), 0) - COALESCE((SUM(ra.debit) - SUM(ra.credit)), 0)
- COALESCE(SUM(cr.credit_value), 0)), 0) AS total
FROM groupmember gm
LEFT JOIN runningaccount ra
ON ra.group_id = gm.groupid
AND ra.ticket_no = gm.tktno
AND gm.memberid = ra.member_id
AND gm.id = ra.group_member_id
LEFT JOIN chitreceipt cr
ON gm.groupid = cr.groupid
AND gm.memberid = cr.memberid
AND gm.tktno = cr.tktno
LEFT JOIN groupnew g
ON g.id = gm.groupid
LEFT JOIN auctionentry ae
ON ae.groupid = gm.groupid
GROUP BY gm.memberid,
gm.groupid,
gm.tktno
這是mySql .. –