jeudi 18 février 2016

Is there a way to make a query follow a hierarchy in SQL?

I have a set of data where I have a bunch of sellers but we have a hierarchy of sellers which we prefer and would like to select the best available seller for each product.

ID |ITEM   | price   | Seller
===========================
1  |Laptop | 100     | eBay
2  |Laptop | 125     | Amazon
3  |Apple  | 5       | Amazon

So when I query out this data for Laptops, I want it each item with the top available seller. And the hierarchy that I have for sellers is 1. ebay 2. Amazon so in essence it would only return the first and the third records.

How would you go about doing this?

Aucun commentaire:

Enregistrer un commentaire