1

Possible Duplicate:
Oracle SQL - How to Retrieve highest 5 values of a column

Hey so I have a query to do this: Write a query which retrieves only the ten companies with the highest number of pickups over the six-month period The 6 months I have been given and I tried many queries this is what I have but I know its wrong as I have no idea

SELECT * FROM 
(SELECT customers.name,COUNT(MANIFEST.MANIFEST_BARCODE) AS Pickups
FROM customers JOIN manifest ON (Reference = pickup_reference) 
ORDER BY Pickups desc;)
WHERE ROWNUM < 11
Community
  • 1
  • 1
TAM
  • 347
  • 4
  • 9
  • 20

1 Answers1

1

Without seeing your table structures etc. I've no idea where the six-month restriction fits in, but for the rest you have an aggregate function (count) without a group by clause, and a random semi-colon in your inner query. Something like this ought to work and is close to what you already have:

SELECT * FROM (
    SELECT customers.name, COUNT(manifest.manifest_barcode) AS Pickups
    FROM customers
    JOIN manifest ON (Reference = pickup_reference)
    GROUP BY customers.name
    ORDER BY pickups DESC
)
WHERE ROWNUM < 11;

There are a lot of examples on this site, like this one for example.

Community
  • 1
  • 1
Alex Poole
  • 183,384
  • 11
  • 179
  • 318
  • Yeah I was on a time limit, bad time management so was rushing, however that works great thanks. – TAM Nov 11 '12 at 23:21