1

I basically need this with some adjustments, I just can't seem to figure it out how to do it. I need to sum the rows of two tables, for example:

SELECT
  student.StudentID,
  student.`Name`,
  COUNT(attendance.AttendanceID) AS Total
FROM
  student
LEFT JOIN attendance ON student.StudentID = attendance.StudentID
GROUP BY student.StudentID,student.`Name\`;

This would return

+-----------+-------------------+-------+
| StudentID | Name              | Total |
+-----------+-------------------+-------+
| k1052280  | Ali Shaikh        |     2 |
| k1052287  | McKenzie Roth     |     2 |
| k1052288  | Dacey Sullivan    |     1 |
| k1052294  | Zelda Cantu       |     0 |
| k1052295  | Kimberly Melton   |     3 |
| k1052296  | Tatianna Cantrell |     0 |
| k1052297  | Morgan Thornton   |     0 |
| k1052298  | Allistair Barlow  |     0 |
| k1052299  | Troy Fulton       |     0 |
+-----------+-------------------+-------+

Total being the rows for the attendance table/student. I need to add in another table, for example meetings, i need a SUM of the two, so the total should be the sum of meetings + attendances for each student.

1
  • Calculate (StudentID, COUNT(AttendanceID)) in subquery. Do the same with meetings. Join these 2 subqueries to student table and obtain/calculate the result you need. Commented Nov 11, 2018 at 6:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.