获取mysql中不同重复ID的计数

获取mysql中不同重复ID的计数,mysql,count,group-by,distinct,having,Mysql,Count,Group By,Distinct,Having,这就是问题所在 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

这就是问题所在

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 ;
结果如下:

+----------+----------------+---------+---------------+------------------------------+-----------------------+
| 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 |
+----------+----------------+---------+---------------+------------------------------+-----------------------+
现在的问题是,正如您在结果集中所看到的,在某些行中,
customer\u id
的最后第二列是重复的,在某些行中是唯一的。最后一列给出了它的计数。
现在,我要选择第三行,有两个客户ID,即51和46,这两个ID在该行中重复,因此此行的最后一列应该包含2。
同样,对于最后一行,我的最后一列应该包含1,因为只有一个重复的
客户id
,即59。
因此,如果您了解确切的问题,那么第二行不应该是此结果集的一部分,因为它不包含任何重复的客户ID。

如何:

group_concat(distinct em.customer_id)


是否要从每行获取不同的em.customer\u Id?ie:60,51,60,51,58,58->60,51,58 | | | | 51,46->0
count(distinct em.customer_id)