H I O X INDIA
MySQL Tutorial
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Templates 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)
Español Français 中文 Deutsch
 Forums   Hosting   Internet Stats   Easy Calculation   FUN Games 

Mysql Tutorial
Introduction
How to Install
Database
Datatypes
Tables
INSERT
SELECT
UPDATE
DELETE
Operators
Functions
Ask Your Doubts
More about Mysql
Feedback




Sorting of Database Datas by Group by Clause


Topic

Query using "Group by" query
How to select the columns using Groupby clause?



Explanation


Group By :

    The Group by clause is used to display the rows and columns grouped by selective columns. It can be used to perform the aggregate functions, such as count().

    The following example query will list the name of the student and also count the repeative names using Group By clause in the select statement.

mysql> select name, count(name) from student group by name;
+-------+-------------+
| name  | count(name) |
+-------+-------------+
| anne  |           2 |
| david |           1 |
| jack  |           1 |
| mille |           1 |
| steve |           2 |
+-------+-------------+
5 rows in set (0.03 sec)
    The below query will display the name and sum of marks of the student using groupby clause.
mysql> select name,sum(marks),count(*) from students group by name;
+----------+------------+----------+
| name     | sum(marks) | count(*) |
+----------+------------+----------+
| anne     |        175 |        2 |
| maichael |         82 |        1 |
| mike     |        182 |        2 |
| rock     |        100 |        1 |
| steve    |        175 |        2 |
+----------+------------+----------+
5 rows in set (0.00 sec)





        MySQL is the most popular open source Relational database Management system (RDBMS). Being a open source anyone can use and change the software for their needs. Hope you enjoy this tutorial. We welcome your Valuable feedbacks or suggestions on this MySQL tutorial. This is a copyright content.


privacy policy     license     sitemap
© 2004-2009 HIOX INDIA - hioxindia.com

Other Links