这是我到目前为止得到的代码
SELECT users_ID,Problem_ID
FROM 'submission'
WHERE Status = "AC"
GROUP BY users_ID,Problem_ID
我得到这些结果
+----------+------------+
| Users_ID | Problem_ID |
+----------+------------+
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 1 |
| 2 | 3 |
+----------+------------+
+----------+------------+
| Users_ID | Problem_ID |
+----------+------------+
| 1 | 3 | -- so because there are 3 results for user_ID 1
| 2 | 2 | -- and there are 2 results for user_ID 2
+----------+------------+
因此,Problem_ID
从每个用户的查询中可以获得多少行。
但是我该怎么做呢?
我忘了提到例如该表包含相同问题的重复项。
我有一个Problem
与ID
的1
,然后在数据库中有可能是使用相同的用户,并作为状态两行"AC"
,但我想只得到其中之一。
这应该工作:
SELECT users_ID, COUNT(DISTINCT Problem_ID)
FROM `submission`
WHERE Status = 'AC'
GROUP BY users_ID
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句