SELECT n.pk_id, count( DISTINCT r.user_id ) forwardNum FROM news_info n INNER JOIN news_info_record r ON r.type = 1 AND r.news_id = n.pk_id AND r.data_active = 0 AND n.data_active = 0 GROUP BY r.news_id
按照news_id分组统计,但是在user_id相同的时候不能统计在内
mysql按照某一个条件进行分组统计,同时又要保证一个相同字段的数据只统计一次
原文:https://www.cnblogs.com/huqi96/p/13961405.html