In the above query, the total row displayed as last row is appended to your original table using UNION ALL. Select 'Total' order_date,sum(sale) from sales In this approach, we SUM the data and simply append it to our original table using UNION ALL clause, as shown below mysql> select * from sales So those working with older versions will need to use UNION ALL. ROLLUP function was added to MySQL from probably version 5.0. We will look at 2 ways to add total row in MySQL – using UNION ALL and ROLLUP. mysql> create table sales(order_date date,sale int) Let’s say you have the following table sales(order_date, sale). Here are the steps to add total row in MySQL. There are 2 ways to add total row in MySQL, using UNION ALL and ROLLUP. Many times, you need to report data in a MySQL table, along with totals.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |