12,757,627 members (36,778 online)
Rate this:
See more:
I want help with SQL statement that can sum the top nth row of a particular column.
something like this
SELECT TOP 3 SUM(GRADE) AS mySUM FROM CALAGR(this gives me the sum of all the rows.I want the sum only up to the the nth row)
Posted 6-Oct-12 1:12am

Rate this:

## Solution 1

REfere this and develope your own query

```SELECT sum(salary)
FROM (SELECT ROW_NUMBER() OVER (ORDER BY empid) AS Row, empid,salary
FROM Emp ) us
WHERE Row <4```
Rate this:

## Solution 2

select sum(grade) as column_name,* from
(select top 3 * from calagr)

first select the top rows you want to, you can add any condition in it too. after your select statement is complete, enclose it in parentheses and at the top of it apply your function (like sum here).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 Graeme_Grant 524 Karthik Bangalore 204 Jochen Arndt 135 Richard Deeming 120 Richard MacCutchan 115
 OriginalGriff 4,177 Peter Leow 3,219 Karthik Bangalore 2,574 ppolymorphe 2,524 Graeme_Grant 2,247

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 6 Oct 2012