The report aims to provide a prioritized list of products, showing more expensive items first but, within the same price range, listing products with lower stock to highlight potential restocking needs. Additionally, within the same price and stock level, products will be listed alphabetically by name.
Here’s how the SQL query would look for sorting the Products
table based on these criteria:
SELECT
ProductID,
ProductName,
Price,
Stock
FROM Products
ORDER BY Price DESC, Stock ASC, ProductName ASC;
ProductID
, ProductName
, Price
, and Stock
from the Products
table.Price DESC
: Products are ordered by price in descending order, starting with the most expensive.Stock ASC
: Within the same price category, products are sorted by stock in ascending order. This helps to identify products that are priced the same but may require urgent restocking.ProductName ASC
: Lastly, if products have the same price and stock level, they are ordered alphabetically by product name. This ensures a consistent order for products with similar price and stock characteristics.Assuming we have a hypothetical set of product data, the output might look something like this in a tabular format:
ProductID | ProductName | Price | Stock |
---|---|---|---|
102 | Luxury Watch | 500.00 | 5 |
101 | Designer Bag | 450.00 | 3 |
105 | High-end Headphones | 450.00 | 15 |
108 | Gourmet Chocolate | 120.00 | 10 |
103 | Organic Tea | 120.00 | 2 |
107 | Handmade Soap | 15.00 | 20 |
106 | Scented Candle | 15.00 | 50 |