解决QUERY以展示TOP 5畅销产品

A4 *_*age 1 sql oracle sqlplus

我有一个表Customer_Invoice具有列item_nameQuantity.我想显示特定商品的前5个商品和按降序销售的商品数量,即如果商品A的商品数量已售出5且商品B的商品数量已售出3则商品A应该在顶部,而商品B将在在第二个号码.

|  ITEMCODE | QUANTITY |
------------------------
|     kb434 |        1 |
| A4tech123 |        4 |
|   HDD40GB |        4 |
|    Cell12 |        4 |
|    Icd123 |        2 |
| A4tech123 |        6 |
Run Code Online (Sandbox Code Playgroud)

在上面的图表中,我希望A4tech123HDD40GB第二个没有,Cell12在第三个没有,依此类推.

mca*_*lex 8

select top 5 Item_code, sum(Quantity)
from customer_invoice
group by Item_code
Order by sum(Quantity) desc
Run Code Online (Sandbox Code Playgroud)