Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Related Tutorials


 
 

Share on Google+Share on Google+

MySQL by

Advertisement
In the following example you will see the how to use the MySQL by. Here, we will use GROUP BY clause. It displays the data in the group of employee salary.

MySQL by

     

In the following example you will see the how to use the MySQL by. Here, we will use GROUP BY clause. It displays the data in the group of employee salary. The GROUP BY statement is used with aggregate functions to group the result.

 

 

 

 

 

Table: employee

CREATE TABLE `employee` ( 
`emp_id` int(11) NOT NULL auto_increment, 
`emp_name` varchar(10) character set utf8 NOT NULL, 
`emp_salary` int(11) NOT NULL, 
`emp_startDate` datetime NOT NULL, 
`dep_name` varchar(50) NOT NULL, 
PRIMARY KEY (`emp_id`) 
)

Query to select all data

SELECT * FROM employee;

It displays the data as follow:

Query to use GROUP BY:

SELECT  dep_name, SUM(emp_salary)  FROM employee GROUP BY dep_name;

The above query sums the employee salary having same department name and shows it in one row. you get the following output:

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 20, 2009

Related Tutorials

Discuss: MySQL by  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com