Hi, Iam new to Mysql.I created a table as given below.I want to show the sum of the column values at the bottom of the table (i.e.at Last Row) as Total. Please tell me the query for that. create table employee ( id INT AUTO_INCREMENT PRIMARY KEY, name varchar(20), dept varchar(10), site varchar(20), dailywage int(10), dailyallowance int(10), dailyexpense int(10) ); insert into employee values(100,'Ben','Sales','ada',200,100,50); insert into employee values(200,'Jack','Technology','ann',200,100,50); insert into employee values(300,'Matt','Technology','nam',200,100,50); insert into employee values(400,'Nami','Marketing','man',200,100,50); insert into employee values(500,'Randy','Technology','kuk',200,100,50); +-----+---------+------------+--------------+-----------+----------------+--------------+ | id | name | dept | site | dailywage | dailyallowance | dailyexpense | +-----+---------+------------+--------------+-----------+----------------+--------------+ | 100 | Ben | Sales | ada | 200 | 100 | 50 | | 200 | Jack | Technology | ann | 200 | 100 | 50 | | 300 | Matt | Technology | nam | 200 | 100 | 50 | | 400 | Nami | Marketing | man | 200 | 100 | 50 | | 500 | Randy | Technology | kuk | 200 | 100 | 50 | +-----+---------+------------+--------------+-----------+----------------+--------------+ Total: 1000.00 500.00 250.00 Help is appreciated.
Select sum(dailywage), sum(dailyallowance), sum(dailyexpense), id, name, dept, site from employee group by id, name, dept, site;
You can try this query, SELECT name, dept, site, IFNULL(id, 'TOTAL') AS id, SUM(dailywage) AS WAGE, SUM(dailyallowance) AS ALLOWANCE, SUM(dailyexpense) AS EXPENSE FROM employee GROUP BY id WITH ROLLUP; Code (markup): regards, --amrush