On the usage of group by in SQL statement

Time:2021-9-11

Group by is a grouping query. Generally, group by is used in conjunction with aggregation functions. You can think about it

You used group   By press   If the item.itemnum field is grouped, the contents of other fields are different. How to display it when it becomes one to many, as shown below

A  B
1  abc
1  bcd
1  asdfg

select A,B from table group by A
What did you say was the result,

A  B
    abc
1  bcd
    asdfg

How to turn the three on the right into one, so you need to use aggregation functions, such as

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

Group by has a principle that in all columns after select, columns that do not use aggregate functions must appear after group by