计算学校收到的费用总额

时间:2014-11-30 09:38:14

标签: sql database phpmyadmin

我正在使用phpMYAdmin,但我无法计算学校收到的费用总额。

FeeTable

Status     FeeReceived
Yes         100
No          200

RegTable

Status     School
Yes        A
Yes        B
No         C
No         C
No         C
No         D
No         E
No         E
No         E
Yes        A
Yes        A
Yes        F
Yes        F
Yes        F
Yes        F
No         G
Yes        H
Yes        H
No         I
No         J
No         K
No         L

我只能计算Status = Yes或Status = No。

的总费用

1 个答案:

答案 0 :(得分:-1)

如果您希望总数为“是”,则总数为“否”

SELECT Sum(f.FeeReceived) As FeeReceived, r.Status FROM RegTable r JOIN FeeTable f ON f.Status = r.Status GROUP BY r.Status 

如果你想通过学校的状态:

SELECT Sum(f.FeeReceived) As FeeReceived, r.Status, r.School FROM RegTable r JOIN FeeTable f ON f.Status = r.Status GROUP BY r.Status , r.School

学校总数:

  SELECT Sum(f.FeeReceived) As FeeReceived, r.School FROM RegTable r JOIN FeeTable f ON f.Status = r.Status GROUP BY  r.School