using ROWNUM
655807Aug 19 2008 — edited Aug 20 2008I am trying to return locations from a query by top ten information cost, but there is a catch, the query should be able to account that two locations may have the same cost if that was the case then the query should return eleven values and not just ten.
The query that ive done so far ( which is pasted below) is able to return the rows by their top ten information cost only, and in the results there are actually two locations that have the same info. cost which means the query should be returning 11 rows not 10. I have not been able to figure out how to return 11 rows yet.Can any one please let me know how to go about getting the 11 rows
SELECT
*
FROM
(
SELECT
l.location_id, sum(ac.cost) COSTS
FROM
targets t
INNER JOIN
locations l
ON
t.location_id = l.location_id
INNER JOIN
missions m
ON
m.location_id=l.location_id
INNER JOIN
access_cost ac
ON
m.security_level BETWEEN
(ac.lower_bound_level) AND
(ac.upper_bound_level)
WHERE
l.location_id IN
(
SELECT
location_id
FROM
targets
HAVING
COUNT( target_id) > 3
GROUP BY
location_id
)
GROUP BY
l.location_id
ORDER BY
COSTS desc
)
WHERE
rownum <=10
;