Interview Question

What is SUM()?

SUM adds non-null values and returns NULL for an empty input set.

💡 Concept ✅ Quick Revision 🗃️ SQL

Answer

SUM adds the non-null input values in a group. • It is used with numeric values and supported interval types. • If no rows are selected, SUM returns NULL rather than zero. • COALESCE can supply zero when that is the required presentation.

💡 SQL Example

SELECT SUM(amount) FROM payments WHERE paid = true;

Result

1250.00

⚡ Quick Revision

SUM adds non-null values and returns NULL for an empty input set.