H I O X INDIA
MySQL Tutorial
Google
Web hscripts.com
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Directories 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)   Bookmarks :-)  
 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
Feedback





Group by Clause


Topic

Query using Group by.
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)


others


        MySQL is the most popular open source database Management system. 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-2005 HIOX INDIA - hioxindia.com

Other Links