Hi folks,
I tried out the solution posted, to get top 2 values per group. It runs but I get every order for each sales rep,
not just the TOP 2.
Any thoughts why the TOP 2 filter is not working?
SQL below. (This attracted a long thread a couple of weeks back.)
--------------------------------
Schema uses 3 tables:
T_ORDERTOTALS
Order Total
CustID (FK to T_CUSTOMER)
T_CUSTOMERS
CustID
RepID (FK to T_SALESREPS)
T_SALEREPS
RepID
RepName
========================================
SELECT
O.OrderTotal,
S.repID
FROM
OrderTotals O,
customers C,
salesreps S
WHERE
O.customName = C.customName AND
C.repID = S.repID AND
OrderTotal IN
(SELECT TOP 2 OrderTotal
FROM OrderTotals
WHERE
customName = C.customName AND
C.repID = S.repID
ORDER BY OrderTotal DESC
)
ORDER BY
S.repID,
O.OrderTotal DESC
Thanks
== eom ===
I tried out the solution posted, to get top 2 values per group. It runs but I get every order for each sales rep,
not just the TOP 2.
Any thoughts why the TOP 2 filter is not working?
SQL below. (This attracted a long thread a couple of weeks back.)
--------------------------------
Schema uses 3 tables:
T_ORDERTOTALS
Order Total
CustID (FK to T_CUSTOMER)
T_CUSTOMERS
CustID
RepID (FK to T_SALESREPS)
T_SALEREPS
RepID
RepName
========================================
SELECT
O.OrderTotal,
S.repID
FROM
OrderTotals O,
customers C,
salesreps S
WHERE
O.customName = C.customName AND
C.repID = S.repID AND
OrderTotal IN
(SELECT TOP 2 OrderTotal
FROM OrderTotals
WHERE
customName = C.customName AND
C.repID = S.repID
ORDER BY OrderTotal DESC
)
ORDER BY
S.repID,
O.OrderTotal DESC
Thanks
== eom ===