Group By usage

Source: Internet
Author: User

Aggregate functions
SUM ()

COUNT function -- COUNT ()

MAX/MIN functions-MAX ()/MIN ()

Mean function-AVG ()

-----------------------------------------

Group by is a GROUP query. Generally, group by is used with Aggregate functions.

You use group by to group by the ITEM. ITEMNUM field. If the content of other fields is different, how can this problem be displayed?

A B
1 abc
1 bcd
1 asdfg

Select A, B from table group by
What are the results,

A B
Abc
1 bcd
Asdfg

How do the three entries on the right become one? So we need to use aggregate functions, such

Select A, count (B) quantity from table group by
The result is
A quantity
1 3

--------------------------------------

Store_Information table

Store_name Sales Date

Los Angeles $1500 Jan-05-1999

San Diego $250 Jan-07-1999

Los Angeles $300 Jan-08-1999

Boston $700 Jan-08-1999

Let's get
SELECT store_name, SUM (Sales) FROM Store_Information group by store_name

Result:

Store_name SUM (Sales)

Los Angeles $1800

San Diego $250

Boston $700

----------------------------------------

The principle of group by is that all columns after select do not use aggregate functions and must appear after group.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.