MySQL + SQL · Lesson 64

SQL से Fee Summary Query

लक्ष्य

Fee summary बनाएं: हर student ने कितना दिया, और किस पर अभी बकाया है।

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 उन students को रखता है जिन्होंने कुछ नहीं दिया; IFNULL उनका total 0 दिखाता है।

सारांश

  • LEFT JOIN + GROUP BY + SUM per-student fee summary बनाता है।
  • IFNULL missing totals को 0 करता है ताकि हर student दिखे।
🔗

Share this topic with a friend

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

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

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

💻 लाइव कोड एडिटर

इस पेज के प्रोग्राम यहीं तैयार हैं — चलाएँ, बदलें और सीखें। कुछ भी इंस्टॉल किए बिना।
OneCompiler द्वारा संचालित। कोड एडिटर में अपने आप आ जाता है — Run दबाकर आउटपुट देखें। अगर एडिटर न खुले तो नए टैब में खोलें.