• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 211
  • Last Modified:

Help writing a specific query please!

I need help writing this query for Sql Server.  

The table appears as:  

GalleryImageID (primary key)
GalleryID (FK)
Hits (bigint)
Total Raiting (bigint)

So there will be many images listed here with the same GalleryID, each with how many hits that image recieved and it's total raiting score.

I need 2 different queries.   I want to know the overall top galleryid's based on hits.  So it will have to go through, find all of the images for a single galleryid and add them up, do this for the several hundred thousand galleries that exist and then return the ones that have the top 10 or 20 or whatever.

Any help?
1 Solution
Guy Hengel [angelIII / a3]Billing EngineerCommented:
select top 1 g.galleryid
from yourtable g
group by g.galleryid
order by sum(g.[Total rating]) desc

stryjewsAuthor Commented:
You rock!  Thanks!

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now