2

我从下面的查询中得到

SELECT co.mobility_theme, COUNT(DISTINCT ca.user_id) AS n 
FROM courses_apply AS ca LEFT JOIN dy41s_courses AS co ON ca.course_id = co.id 
WHERE ca.submission IS NULL AND ca.`call` LIKE  '1b' 
GROUP BY co.mobility_theme 
ORDER BY co.mobility_theme ASC 

以下结果总计 (133)

mobility_theme n

1 =>70

4 =>18

5 =>45

我想要做的是:对于每个移动主题(1,2 和 5),我都有重复的用户,所以唯一的 user_id 应该是(130),我无法通过(移动主题)获得唯一的 user_id 组,任何帮助?

4

1 回答 1

3

一种方法是任意选择一个移动主题。此方法选择具有最小值的方法:

select mobility_theme, COUNT(*) as Numusers
from (select ca.user_id, MIN(co.mobility_theme) as mobility_theme
      from courses_apply ca LEFT JOIN
           dy41s_courses co
           ON ca.course_id = co.id 
      WHERE ca.submission IS NULL AND ca.`call` LIKE  '1b' 
      group by ca.user_id
     ) caco
group by mobility_theme
于 2013-05-15T14:27:48.617 回答