MariaDB SUM function is used to return the summed value of an expression.
If the table has no any rows, then SUM () returns NULL. The DISTINCT keyword is also used with SUM () to sum only the distinct values of an expression.
Syntax:
SELECT SUM(aggregate_expression)
FROM tables
[WHERE conditions];
Example
CREATE TABLE EMP (emp_id, emp_salery);
INSERT INTO EMP VALUES (1,1000),(2,2000),(3,5000);
SELECT *FROM EMP;
Table: EMP
emp_id emp_salery
1 1000
2 2000
3 5000
SELECT SUM (emp_salery) FROM EMP WHERE emp_id>2;
MariaDB interview questions
Output:
5000