Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 sql query to count term hits (like search count)

Author  Topic 

jon.a.smith
Starting Member

1 Post

Posted - 2008-08-13 : 13:12:34
table:
date
term
count

i have a table specified above that i increment the count on each time a ui field is selected. this count is good for a day. i'd like to be able to query the table for a date range and find the top X terms based on the count summary for the date range (not single day). any ideas?
thanks.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-13 : 13:15:47
[code]SELECT TOP X term
FROM
(SELECT term,sum(count) as total
FROM table
WHERE date BETWEEN @StartDate AND @EndDate
GROUP BY term
)t
ORDER BY total DESC
[/code]

@StartDate and @EndDate variable values represent your daterange.
Go to Top of Page
   

- Advertisement -