mysql - SQL COUNT on GROUP BY -


this code got far

select users_id,problem_id  'submission' status = "ac"  group users_id,problem_id  

i getting these results

+----------+------------+ | users_id | problem_id | +----------+------------+ |        1 |          1 | |        1 |          2 | |        1 |          3 | |        2 |          1 | |        2 |          3 | +----------+------------+ 

i want get

+----------+------------+ | users_id | problem_id | +----------+------------+ |        1 |          3 | --  because there 3 results user_id 1 |        2 |          2 | -- , there 2 results user_id 2 +----------+------------+ 

so problem_id how many rows getting query each user.
how accomplish this?

edit:

i forgot mention table contains duplicates of same problem example.
got problem id of 1 , in database there 2 rows same user , status "ac" want 1 of them.

this should work:

select users_id, count(distinct problem_id) `submission` status = 'ac'  group users_id 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -