Excel uses pivot tables to count the number of unique values

The sample data source format is as follows. Now we need to count the number of people with uid in each group:

By default when using a pivot table, you can only select "Count" to get the number of rows for each group, and the uid is not deduplicated;

Mysql column conversion group_concat function

The group_concat function in MySQL can combine the specified fields of the group into one row of content, which is more suitable for column conversion.

The complete syntax is as follows:

group_concat([DISTINCT] Field to be concatenated [Order BY ASC/DESC sorting field] [Separator 'separator'])

The default delimiter is comma

Example:

select id,group_concat(distinct name) from table group by id;  

It should be noted that there is a default limit on the length of the merged fields.


refer to:

Subscribe to statistics