Oracle Query – Listing the Most Popular Item Being Ordered

oracle

I have the following tables:

ITEM (Item#, Item_Name, Unit_Price)

ORDER_ITEM (Order#, Item#, Qty)

How do I list the most popular item being ordered ?

I'm using Oracle SQL Developer. It is popular by most Qty sold.

Best Answer

To understand the logic I suggest you read this.

http://www.w3resource.com/sql/aggregate-functions/count-with-group-by.php

Try this:

SELECT Item#, SUM(Qty) AS SoldQty
FROM ORDER_ITEM
GROUP BY Item#
ORDER BY SoldQty --You can use 'Desc' depending on how you want to see the data
  ;