If we want to sum same column’s value, we must use sum() aggregate function.
Example: Find the total page count of all books.
Answer:
1 |
Select sum(pageCount) from books. |
If we want to sum different columns value then we must use + (plus) operator on the query.
Example: List pagecount, point and sum of pagecount and point columns values.
1 |
Select pagecount, point, point + pagecount as total from books. |
If we want to find sum of two variables value then the example below.
Example
1 2 3 |
Set @a = 5; Set @b = 10; Select @a + @b as total; |