GROUP BY
To group a query by using the GROUP BY clause Union aggregate function:
Group BY is used to group the result set in pairs, and each group of segments is summarized.
Syntax format: GROUP BY column name [having conditional expression]
It is grouped by the specified columns, the same records in that column are made into a group, each group is evaluated, and having the grouped records are filtered, where clauses are filtered before they are summarized.
Note: The columns displayed in the SELECT statement are the columns that participate in the calculation and the columns in the GROUP BY clause.
Example: Select Egg_liang, Count (Egg_jia) as number, sum = SUM (Egg_jia)
(Columns to display)
From egg
GROUP BY Egg_liang-----> Columns to group (must be the same as above)
Having sum (Egg_jia) > 250
COMPUTE BY
Use the COMPUTE BY clause: It is used to group all of the data in the result set, and the difference between it and group by IS that compute by not only displays summary data, but also shows the record details of participating totals.
Syntax format: COMPUTE aggregate function [by column name]------> "aggregate function" can write multiple
Note: You must sort the summarized columns before you can summarize them with compute by.
Cases
SELECT * from Qian ORDER by Biao_jia Compute sum (biao_liang) by Biao_jia
(Columns to sort) (columns to summarize) (must be the same as the columns to be sorted)
GROUP BY and compute by in SQL