• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • 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!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

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