| id | courseID | courseType |
+-----------+-------------+----+
| 1 | 0 | 2 |
| 2 | 2 | 2 |
| 3 | 0 | 0 |
| 4 | 10 | 4 |
| 5 | 2 | 2 |
| 6 | 0 | 0 |
| 7 | 0 | 0 |
| 8 | 5 | 2 |
| 9 | 5 | 2 |
| 10 | 5 | 2 |
+-----------+-------------+----+
我想首先列出所有CourseID,其课程类型为
| courseID | courseType |
+-----------+-----------+
| 5 | 2 |
| 2 | 2 |
| 10 | 4 |
+-----------+-----------+
答案 0 :(得分:1)
select distinct top 3 courseID,courseType
from table
order by courseID,courseType desc
答案 1 :(得分:0)
select distinct courseID, courseType
from your_table
where 0 not in (courseID, courseType)
order by courseID desc
答案 2 :(得分:0)
为了获得出现次数最多的courseId, courseType
对并使用0
省略其中的任何一对,您应该运行此查询:
SELECT courseId, courseType FROM t
WHERE 0 NOT IN (courseId, courseType)
GROUP BY courseId, courseType
ORDER BY count(*) DESC