我必须计算加入表格后得到的一列的总和
SELECT
fee_amount
FROM bill
INNER JOIN status
ON bill_status_id=status_id
INNER JOIN user
ON bill_user_id =user_id
WHERE bill_active='Y'
我必须计算此后返回的fee_amount的SUM,我可以使用下面的一个吗?
SELECT
SUM(fee_amount)
FROM (
SELECT
fee_amount
FROM bill
INNER JOIN status
ON bill_status_id=status_id
INNER JOIN user
ON bill_user_id =user_id
WHERE bill_active='Y'
)
请建议。
答案 0 :(得分:1)
您不需要使用子查询,只需在第一个查询中添加SUM
即可。
SELECT
SUM(fee_amount)
FROM bill
INNER JOIN status
ON bill_status_id=status_id
INNER JOIN user
ON bill_user_id =user_id
WHERE bill_active='Y'