sql查询以获得最高结果

时间:2011-05-19 13:55:13

标签: sql sql-server-2008

之前我曾问过类似的问题,但由于我没有得到答复,所以我希望它能更好一点。

我有一个包含谷歌类型结果的记录表,例如某个术语有特定数量的记录。我想要一个查询,它将选择给定日期的条款,每个项目的结果数量按降序排列。

示例表

term      dateadded    resulturl
marines   2011-05-19   http:.../

2 个答案:

答案 0 :(得分:2)

SELECT term, COUNT(*) AS TermCount
    FROM YourTable
    WHERE dateadded = @YourDate
    GROUP BY term
    ORDER BY TermCount DESC

答案 1 :(得分:0)

Select term
  , Count(*) as Result_Count
from TableName
where dateadded = @GivenDay -- don't know if time is a factor
group by term
order by result_count desc