2013-10-11 51 views
-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所有CourseID作爲我sqlquery的可以顯示。熱門

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

如果你想獲得'courseId,courseType'對的出現次數,那麼你必須使用'group by' –

回答

0
select distinct courseID, courseType 
from your_table 
where 0 not in (courseID, courseType) 
order by courseID desc 
+0

它的工作,..! – user2431105

+0

我更新了答案。請不要在未來的其他用戶答案中提問。 –

1
select distinct top 3 courseID,courseType 
from table 
order by courseID,courseType desc 
0

爲了得到courseId, courseType對最事件和漏報任何一個其中有0您應該運行此查詢:

SELECT courseId, courseType FROM t 
WHERE 0 NOT IN (courseId, courseType) 
GROUP BY courseId, courseType 
ORDER BY count(*) DESC