MySQL + SQL · Lesson 64

Fee Summary Query Using SQL

Goal

Produce a fee summary: how much each student has paid, and who still owes money.

The Query

SELECT s.name,
       IFNULL(SUM(f.amount), 0) AS total_paid
FROM students s
LEFT JOIN fees f ON s.roll_no = f.roll_no
GROUP BY s.name
ORDER BY total_paid DESC;
LEFT JOIN keeps students who paid nothing; IFNULL shows their total as 0.

Summary

  • LEFT JOIN + GROUP BY + SUM builds a per-student fee summary.
  • IFNULL turns missing totals into 0 so every student appears.
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

WhatsApp