Use GROUP BY : Group « Select Clause « SQL / MySQL

Home
SQL / MySQL
1.Aggregate Functions
2.Backup Load
3.Command MySQL
4.Cursor
5.Data Type
6.Database
7.Date Time
8.Engine
9.Event
10.Flow Control
11.FullText Search
12.Function
13.Geometric
14.I18N
15.Insert Delete Update
16.Join
17.Key
18.Math
19.Procedure Function
20.Regular Expression
21.Select Clause
22.String
23.Table Index
24.Transaction
25.Trigger
26.User Permission
27.View
28.Where Clause
29.XML
SQL / MySQL » Select Clause » Group 
Use GROUP BY
   
  
Drop table sales;
  
CREATE TABLE sales(
    num MEDIUMINT NOT NULL AUTO_INCREMENT,
    name CHAR(20),
    winter INT,
    spring INT,
    summer INT,
    fall INT,
    category CHAR(13),
    primary key(num)
)type=MyISAM;


insert into sales value(1'Java', 1067 200150267,'Holiday');
insert into sales value(2'C',970,770,531,486,'Profession');
insert into sales value(3'JavaScript',53,13,21,856,'Literary');
insert into sales value(4'SQL',782,357,168,250,'Profession');
insert into sales value(5'Oracle',589,795,367,284,'Holiday');
insert into sales value(6'MySQL',953,582,336,489,'Literary');
insert into sales value(7'Cplus',752,657,259,478,'Literary');
insert into sales value(8'Python',67,23,83,543,'Holiday');
insert into sales value(9'PHP',673,48,625,52,'Profession');

select from sales;


/*Change the GROUP BY field to cust_city, to list all the unique cities and their states, including both cities from CA.
*/
SELECT FROM sales
GROUP BY catagory;


           
         
    
    
  
Related examples in the same category
1.Use GROUP BY clause to list only the unique data
2.Another GROUP BY
3.GROUP BY with order and HAVING
4.Use GROUP BY 2
5.Use GROUP BY and ORDER BY together
6.Get GROUP BY for COUNT
7.Simple GROUP BY
8.GROUP and sort the records
9.GROUP value and count
10.Grouping Data: Filtering Group Data
11.Grouping Data: 03 Using the HAVING Clause 1
12.Grouping Data: Using the HAVING Clause 1
13.Using math function in HAVING
14.GROUP and HAVING with sub query
15.Group by and order by for linked tables
16.Grouping by Expression Results
17.Give the expression an alias in the output column list and refer to the alias in the GROUP BY clause
18.Write the GROUP BY clause to refer to the output column position:
19.Group by multiple expressions if you like.
20.Group mail table records into categories of 100,000 bytes
21.Group by DAYOFWEEK( )
22.Working with Per-Group and Overall Summary Values Simultaneously
23.Finding Rows Containing Per-Group Minimum or Maximum Values
24.Maximum-per-group problem for this table
25.Another way to group statements is to turn off auto-commit mode explicitly.
26.To use a GROUP BY clause effectively, you should also include a select list element that contains a function t
27.Specifies two columns in the GROUP BY clause
28.Working with Grouped Data
29.Group by calculated value
30.Group value in subquery
31.Group by two columns
32.Group by then order by vs Group by only
33.GROUP BY for Several Columns
34.GROUP BY returns a final sum for the first column and supplementary partial sums for the second column.
35.Dividing a Summary into Subgroups
36.Use the name column to place the rows in groups, but the summary functions operate on the miles values:
37.Parentheses may be used to group alternations.
38.To be more specific and find out how many messages each sender sent from each host, use two grouping columns.
39.Categorize groups on a logarithmic scale.
40.Missing and non-missing counts can be determined for subgroups as well.
41.get the number of orders per customer
42.A less fine-grained summary can be obtained by using only the month values
43.Find out how many books you have per author, use this query
44.Ascertain the most common initial letter for state names like this:
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.