Results 1 to 1 of 1

Thread: sql server query for report

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2008
    Location
    USA
    Posts
    257

    sql server query for report

    I am trying to design a reporting service and some of the queries are not correctly constructed.

    1 - select the top 50 terms that produce the most results for today:

    2 - select the top 50 terms that produce the least results for today:

    3 - select the top 10 terms with most results for the last 10 days



    Table A

    clientId searchterm count dateadded
    0001 ping 5000 2011-05-15 12:00:00 00

    This is what I have for 3:

    Code:
    with tmp as( 
    select clientid, searchterm, count(1) as TermResults, DENSE_RANK() OVER 
        (partition by clientid 
          ORDER BY clientId, count(1) DESC) as rnk  
         from TFeed where dateadded >getdate() - 10 
         and not searchterm is null  
         group by clientId, searchterm)  
    select * from tmp where rnk < 11
    Last edited by Hack; May 18th, 2011 at 12:02 PM.
    -- Please rate me if I am helpful --

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width