Table
products
6 columns · 1 foreign keys · referenced by 1 tables
Columns
| # | Name | Type | Key |
|---|---|---|---|
| 01 | product_id | SERIAL | PK |
| 02 | name | VARCHAR(200) | |
| 03 | cat_id | INT | FK |
| 04 | price | NUMERIC | |
| 05 | cost | NUMERIC | |
| 06 | stock | INT |
Outgoing references
- cat_id — references another table
Referenced by
Example queries against this table
- Select first 5 products by price descendingSQL
SELECT product_id, name, price, stock FROM products ORDER BY price DESC LIMIT 5; - Show total sum of all product prices in stockSQL
SELECT SUM(price * stock) AS total_inventory_value FROM products WHERE is_active = TRUE; - Show products with stock between 10 and 100SQL
SELECT name, price, stock FROM products WHERE stock BETWEEN 10 AND 100 ORDER BY stock; - Show products with profit margin percentageSQL
SELECT name, price, cost, ROUND((price - cost) / price * 100, 2) AS margin_pct FROM products WHERE cost IS NOT NULL AND cost > 0 ORDER BY margin_pct DESC;