Jow can I return two highest aggregated results?
For example, I have a result like this:
CustomerId Total
---------------------
5 1100.00
n/a 100.00
7 100.00
6 0.00
and I need to return max 2 highest rows like this:
CustomerId Total
-----------------------
5 1100.00
7 100.00
n/a 100.00
I tried with TOP 2
, but the problem is that I do not know how can I return more rows if there are rows with the same value.
Here is my query at the moment
SELECT
ISNULL(CONVERT(varchar(50), u.CustomerId), 'not found') CustomerId ,
ISNULL(SUM(o.Total), 0.00) Total
FROM
Orders o
FULL OUTER JOIN
CustomerId u ON u.UserId = o.UserId
GROUP BY
u.CustomerId
ORDER BY
Total DESC;