2

I am getting from the below query

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 

The below result total (133)

mobility_theme n

1 =>70

4 =>18

5 =>45

What I want to do is: for each mobility theme (1,2 and 5), I have repeated users, so the total unique user_id should be (130), I cannot manage to get unique user_id group by (mobility theme), any help?

10
  • not to the point but what is up with your like clause ? Commented May 15, 2013 at 13:44
  • It is only to get the records of specify "call" Commented May 15, 2013 at 13:52
  • i know but it is not a 'like' Commented May 15, 2013 at 13:58
  • what am i misunderstanding about your problem, i have a repeat user, i get the expected results. sqlfiddle.com/#!2/11466/1 Commented May 15, 2013 at 14:01
  • maybe you mean a given user, across say 2 courses ? Commented May 15, 2013 at 14:10

1 Answer 1

3

One approach is to arbitrarily choose one of the mobility themes. This method chooses the one with the minimum value:

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.