MySQL + SQL · Lesson 63

Report Card Query Using SQL

Goal

Generate a report card showing each student's total, percentage and grade across subjects.

The Query

SELECT s.name,
       SUM(m.score) AS total,
       ROUND(AVG(m.score), 1) AS percentage,
       CASE WHEN AVG(m.score) >= 90 THEN 'A+'
            WHEN AVG(m.score) >= 75 THEN 'A'
            WHEN AVG(m.score) >= 33 THEN 'Pass'
            ELSE 'Fail' END AS grade
FROM students s JOIN marks m ON s.roll_no = m.roll_no
GROUP BY s.name;

Summary

  • JOIN + GROUP BY totals each student; AVG gives percentage.
  • CASE turns the percentage into a grade in the same query.
🔗

Share this topic with a friend

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

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

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

\n

💻 Live Code Editor

Is page ki language (MYSQL) mein code likhein aur turant chalाएं — yahीं, bina kuch install kiye.
Powered by OneCompiler. Agar editor na khule to yahान naye tab mein kholein.

💻 Live Code Editor

Is page ke program yahan ready hain — chalाएं, badlें aur seekhें. Bina kuch install kiye.
Powered by OneCompiler. Editor mein code apne aap aa jata hai — Run dabaakर output dekhें. Agar load na ho to naye tab mein kholें.