This SQL query joins two tables to retrieve product category descriptions, product IDs, descriptions, and quantity availability. It uses a CASE statement to classify the availability for different product categories as "out of stock", "low stock", "in stock", or "enough stock" based on different quantity thresholds defined for each category.
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
449 views
Project SQL
This SQL query joins two tables to retrieve product category descriptions, product IDs, descriptions, and quantity availability. It uses a CASE statement to classify the availability for different product categories as "out of stock", "low stock", "in stock", or "enough stock" based on different quantity thresholds defined for each category.
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2
select PRODUCT_CLASS_CODE as 'Product Category',
PRODUCT_ID as 'Product ID',
PRODUCT_DESC as 'Product Description', PRODUCT_PRICE as 'Actual Price', CASE PRODUCT_CLASS_CODE WHEN 2050 THEN PRODUCT_PRICE+2000 --increase price for category 2050 when 2051 THEN PRODUCT_PRICE+500 --increase price for category 2051 WHEN 2052 THEN PRODUCT_PRICE+600 --increase price for category 2052 ELSE PRODUCT_PRICE END as 'calculated_price' FROM PRODUCT --descending order by category(product class code) order by PRODUCT_CLASS_CODE DESC;
select PRODUCT_CLASS_CODE as 'Product Category',
PRODUCT_ID as 'Product ID', PRODUCT_DESC as 'Product Description', PRODUCT_PRICE as 'Actual Price', CASE PRODUCT_CLASS_CODE WHEN 2050 THEN PRODUCT_PRICE+2000 --increase price for category 2050 when 2051 THEN PRODUCT_PRICE+500 --increase price for category 2051 WHEN 2052 THEN PRODUCT_PRICE+600 --increase price for category 2052 ELSE PRODUCT_PRICE END as 'calculated_price' FROM PRODUCT --descending order by category(product class code) order by PRODUCT_CLASS_CODE DESC;
SELECT pc.PRODUCT_CLASS_DESC as 'Product Category',p.PRODUCT_ID as'Product
ID' ,p.PRODUCT_DESC as 'Product Description' ,p.PRODUCT_QUANTITY_AVAIL as 'Product Availability' , CASE -- Electronics (2050) and Computers(2053) when pc.PRODUCT_CLASS_CODE in (2050,2053) THEN CASE WHEN p.PRODUCT_QUANTITY_AVAIL=0 then 'out of stock' when p.PRODUCT_QUANTITY_AVAIL<=10 then 'low stock' WHEN (p.PRODUCT_QUANTITY_AVAIL>=11 and p.PRODUCT_QUANTITY_AVAIL<=30) THEN 'in stock' WHEN p.PRODUCT_QUANTITY_AVAIL >=31 THEN 'enough stock' END --stationary(2052) and clothes(2056) WHEN pc.PRODUCT_CLASS_CODE in (2052,2056) THEN CASE WHEN p.PRODUCT_QUANTITY_AVAIL =0 THEN 'out of stock' WHEN p.PRODUCT_QUANTITY_AVAIL<=20 THEN 'low stock' WHEN(p.PRODUCT_QUANTITY_AVAIL >=21 and p.PRODUCT_QUANTITY_AVAIL <=81) THEN 'in stock' WHEN p.PRODUCT_QUANTITY_AVAIL >=81 THEN 'enough stock' END --Rest Category WHEN pc.PRODUCT_CLASS_CODE(3001,3002,2051,2054,2055,2057,2058,2059,2060,3000) THEN CASE WHEN p.PRODUCT_QUANTITY_AVAIL=0 THEN 'out of stock' WHEN p.PRODUCT_QUANTITY_AVAIL<=15 THEN 'low stock' WHEN(p.PRODUCT_QUANTITY_AVAIL>=16 AND p.PRODUCT_QUANTITY_AVAIL <=50) THEN 'in stock' WHEN p.PRODUCT_QUANTITY_AVAIL >=51 THEN 'enough stock' END END FROM PRODUCT join codes on PRODUCT.p=PRODUCT_CLASS.pc;
3----- select CITY FROM ADDRESS WHERE COUNTRY not like 'usa' and COUNTRY not like 'malaysia' order by CITY>1 desc;