0

我需要检索每个学生的值,如下所示

student full name | costs | discounts | net Value | payments | remaining

当我尝试

SELECT 
    concat_ws(' ',students.firstname,students.secondname,students.thirdname,students.forthname,students.lastname),
        students.birthdate,
        sum(costs.value),
        sum(discounts.value),
        sum(costs.value)-sum(discounts.value),
        sum(payments.amount),
        sum(costs.value)-sum(discounts.value)-sum(payments.amount)     

FROM students
JOIN coststudents 
       ON  coststudents.student_id = students.student_id 
 JOIN costs  
    ON  costs.cost_id = coststudents.cost_id
JOIN discountstudent 
       ON  discountstudent.student_id = students.student_id 
JOIN discounts  
    ON  discounts.id = discountstudent.id
JOIN payments 
       ON  payments.student_id = students.student_id 

它只给我一行,并不对应于查询。请帮忙。

4

1 回答 1

1

将 GROUP BY students.student_id 放在代码的末尾。

编辑:改为 JOIN 使用 LEFT JOIN。

于 2013-08-27T00:20:07.010 回答