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
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 agroup byclause, and a random semi-colon in your inner query. Something like this ought to work and is close to what you already have:There are a lot of examples on this site, like this one for example.