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

MySQLMySQLi Database

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.

raja
Published on 22-Feb-2018 10:32:11
Advertisements