In MySQL, how we can get the total value by category in one output row?


With the help of the MySQL SUM() function, we can get the total value by category in one output row. For example in table ‘ratelist’ if we want to get the total value of category ‘price’ then we can use SUM() on price as follows −

mysql> select SUM(price) as totalprice from ratelist;
+------------+
| totalprice |
+------------+
|       3237 |
+------------+
1 row in set (0.00 sec)

The query above returns the total value of price in one output row.

Updated on: 22-Jun-2020

47 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements