Getting the number of different duplicate identifiers in mysql

this is a request

select count(*), ss.pname, ttu.user_id, ttl.location_name , group_concat(em.customer_id), count(em.customer_id) from seseal as ss, track_and_trace_user as ttu, track_and_trace_location as ttl, eseal_mapping as em where ss.real_id=em.e_id and em.user_id=ttu.user_id and ttu.location_id=ttl.location_id group by ss.pname, ttu.user_id, ttl.location_name having count(em.customer_id)>1 ; 

and the following results:

 +----------+----------------+---------+---------------+------------------------------+-----------------------+ | count(*) | pname | user_id | location_name | group_concat(em.customer_id) | count(em.customer_id) | +----------+----------------+---------+---------------+------------------------------+-----------------------+ | 6 | Nokia N91 | 1 | Malad | 60,51,60,51,58,58 | 6 | | 2 | SUPERIA 1000gm | 4 | Raichur | 51,46 | 2 | | 5 | SUPERIA 1000gm | 5 | west bengal | 51,46,51,51,46 | 5 | | 2 | SUPERIA 500gm | 4 | Raichur | 59,59 | 2 | | 3 | SUPERIA 500gm | 5 | west bengal | 59,46,59 | 3 | +----------+----------------+---------+---------------+------------------------------+-----------------------+ 

Now the problem is that, as you can see in the result set, the second last column in some rows of customer_ids is a duplicate and unique in some rows. And the last column gives the score.
Now I want to select the third row, there are two client identifiers, namely 51 and 46, and they are duplicated in this row, so my last column for this row should contain 2.
Similarly for the last row, my last column should contain 1, since there is only one customer id that is duplicated, i.e. 59.
So, if you understand the exact problem, then the second line should not be part of this result set, since it does not contain the identifiers of customers that are duplicated.

+4
source share
1 answer

What about:

 group_concat(distinct em.customer_id) 

and

 count(distinct em.customer_id) 
+1
source

Source: https://habr.com/ru/post/1445047/


All Articles