Table of contents
SQL GROUP BY statement
GROUP BY Statement
The GROUP BY statement is used in conjunction with aggregate functions to group the result set by one or more columns.
#SQL GROUP BY 语法
SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
In short, it is to
column_name
perform the function according to the function. For example, ifcolumn_name
there are multiple repeated data, and the data iscolumn_name2
different, you can call itSUM()
to merge the datacolumn_name2
and select to display it.
topic
10-14 A4-4 Find product information in the product table whose average order quantity is greater than a specific value (20 points)
Find product information in the product table (products) whose total order quantity is greater than 15, displayed as: product number (ProductID), and Total Order Quantity (renamed to sumUnitsOnOrder)
Tip: Please use the SELECT statement to answer.
Table Structure:
table sample
# output sample
the code
SELECT ProductID, SUM(UnitsOnOrder) sumUnitsOnOrder
FROM products
GROUP BY ProductID
Having sumUnitsOnOrder>15
MySQL authentication