Learn group by syntax

group by is often used with aggregate functions.

(1) The fields that appear after the select are either in the aggregate function or in the group by.

(2) If there are other filter conditions, use where first and then use group by, where is higher.

Use the table below to illustrate

a b c
1 a First
1 a First
1 a First
1 a First
1 a Second
1 b Second
1 b Second
1 b Second

select count(a),b from test group by b;

  b
5 a
3 b

select count(a),b,c from test group by c,b;

  b c
  a First
  a Second
  b Second

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325058960&siteId=291194637