2014-03-04 81 views
0

我想從這個查詢從標籤表獲得前10個值的結果,其中最 發佈的文章的SQL Server 2012組通過

select distinct top 10 Name as 'Tag Name' 
from Articles join Tags on Articles.TagID=Tags.ID 
group by Tags.Name 
order by count(Articles.TagID) 

,但它給了以下錯誤

Msg 145, Level 15, State 1, Line 1 
ORDER BY items must appear in the select list if SELECT DISTINCT is specified. 

回答

3

你如果按該列分組,則不需要distinct

select top 10 
     Name as 'Tag Name' 
from Articles 
join Tags on Articles.TagID = Tags.ID 
group by Tags.Name 
order by count(Articles.TagID) desc