For group by personal understanding

Group By

group by, as the name suggests, is to group data. Or it is understood that the data is deduplicated according to the grouped field, and only one piece of data is kept for each value under this field.

But how to operate all the data information under this group, for example, I want to display statistics on the data information of this group, then I need to use the aggregation function.

HAVING is equivalent to conditional screening, but it is different from WHERE screening. HAVING is to filter for GROUP BY objects.

There is another way to use: Use the grouped data as a temporary table, and then use select for queries.

select data.Email  from 
(select *,count(*) as numbers from person group by Email ) as data 
where data.numbers >1;

Group personal feeling is a syntactic sugar, the main steps are as follows: group by email classification

  1. First split the table into n small tables according to the specified grouping. Note that in the process of the difference table, data records that do not meet the where condition will be removed

    The email field of each small table here is the same.

  2. According to constraints, such as select count (), having count to process the records in each small table, generally can only perform statistical operations, such as the average, the maximum value

  3. Then take a piece of data in each small table.

    1. If there is an aggregation function, the result of the aggregation function is returned + the data record spliced ​​from the first data in the small table
    2. There is no aggregate function, directly return the first record of the small table
  4. Finally, the record value returned by each small table is spliced ​​into a complete table.


Guess you like

Origin www.cnblogs.com/jianga/p/12693163.html