-4
| 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      |
+-----------+-------------+----+

我想列出第一个带有 CourseType 的 All CourseID

| courseID | courseType | 
+-----------+-----------+
|  5       |    2       |
|  2       |    2       |
|  10      |    4       |
+-----------+-----------+
4

3 回答 3

1
select distinct top 3 courseID,courseType
from table
order by courseID,courseType desc
于 2013-10-11T14:35:26.817 回答
0
select distinct courseID, courseType
from your_table
where 0 not in (courseID, courseType)
order by courseID desc
于 2013-10-11T14:33:37.413 回答
0

为了获得courseId, courseType出现次数最多的对并用 a 省略其中任何一个,0您应该运行以下查询:

SELECT courseId, courseType FROM t
WHERE 0 NOT IN (courseId, courseType)
GROUP BY courseId, courseType
ORDER BY count(*) DESC
于 2013-10-11T14:41:27.047 回答