473,470 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Find Top Items By Total Score

1 New Member
I have a SQL table called KbRank with the following columns:

KBID RANKINGSCORE
1 100
2 50
1 100
1 75
3 0
5 25
2 100
3 100
1 0

I am attempting to write a SQL query that will find the top 3 KBID's with the highest cummulative ranking score. So I would want to add all of the RANKINGSCORE's for KBID1 up, all of the RANKINGSCORE's for KBID2 up etc, and then sort the results and grab the top 3.

I'm not much of a SQL guru but I think I would need to use a select statement with SUM to accomplish this. Can anyone point me in the right direction or offer any pointers?

Thanks
Brad
May 5 '10 #1
2 2115
jkmyoung
2,057 Recognized Expert Top Contributor
http://www.w3schools.com/sql/sql_groupby.asp

The first example shows you how to get the sum of a group.
From there, sort on the sum,
and then select the first few rows using TOP eg: http://vorg.ca/626-the-MS-SQL-equiva...-limit-command
May 5 '10 #2
pantan
1 New Member
You'll need to use the SUM function and group by to calculate the total for each kbid, and use order by to list the kbid's in descending order. Finally, you'll leverage the subqueryconstruct to find the top 3 kbid's.

The SQL to use (this works in MySQL) is:

select kbid from
(select kbid, sum(rankingscore)
from kbrank
group by kbid
order by sum(rankingscore) desc) li1
limit 3;
May 27 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: andrea.gavana | last post by:
Hello NG, I was wondering if there is a faster/nicer method (than a for loop) that will allow me to find the elements (AND their indices) in a list that verify a certain condition. For example,...
0
by: Manish Baronia | last post by:
Hello All, Is there any C API to find the total VM of a Unix system? TIA, Manish
10
by: Craig Bumpstead | last post by:
Hi, I was wondering the best and fastest way to determine how many lines are in a log file. At the moment I am simply doing a StreamReader.ReadLine and incrementing a counter until I reach...
3
by: Luis Esteban Valencia | last post by:
hello quite a simple one if you understand regular expressions vbscript and ..net, probably quite hard if you don't i have a single line input which offers classic search functionality, so if...
0
by: andreas | last post by:
Hi, I have filled a sortedlist with items of instances of a class and the corresponding keys Now i will have back all the keys and the corresponding properties of the items dim keyitem as...
3
by: lostncland | last post by:
I am working on this program. The array has 10 scores. (there is more to this program.) Does the last "for" section make sense? /*Defines a global constant called N throughout the file. ...
2
Lokean
by: Lokean | last post by:
I have a datagrid that is populated by the results of a function which is fed parameters from my program. I'm searching for machines reporting on a certain status. What I need to do is...
0
by: PZMW8ANrathibha | last post by:
Hai I can suggest me a function that returns the total number of pages in a odp file. Waiting for reply Thank You.
1
by: samueloommen | last post by:
I have a stored procedure which insertts and updates the table, I need to find out how many records got updated after the stored procedure got executed.
6
by: shalskedar | last post by:
In the Report 1 of the fields contain expression.When i m trying to find the grandtotal for this field it gives me error.. For ex- The field expression is Format(,"0.00") to limit the field value...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.