我在两个表上进行了内部联接,并在两个表上联接了“ ID”,我不确定如何获得唯一名称及其所有销售额之和的输出。
SELECT staff.first_name, staff.last_name, payment.amount, staff.staff_id
FROM staff
INNER JOIN payment ON staff.staff_id = payment.staff_id;
这是输出:
答案 0 :(得分:1)
您可以按名称分组,然后将总计sum
函数应用于销售:
SELECT staff.first_name, staff.last_name, SUM(payment.amount)
FROM staff
INNER JOIN payment ON staff.staff_id = payment.staff_id
GROUP BY staff.first_name, staff.last_name