sql-queries-used-in-class
sql-queries-used-in-class
#Question: Find all of the products from the product table which don’t have their
sizes mentioned.
select * from farmers_market.product
where product_size is null;
#final query
select * from farmers_market.product
where product_size is null
or trim(product_size) = '';
select
product_id,
market_date,
quantity,
cost_to_customer_per_qty,
ROUND(quantity * cost_to_customer_per_qty,2) as tot_amount
from farmers_market.customer_purchases
where market_date IN
(
select market_date from farmers_market.market_date_info
where market_rain_flag = 1
);
#Question: List down all the product details where product_category_name contains
“Fresh” in it
#quiz 1
#Select columns from DB.table1 where col1 in (select col1, col2 from DB.table2);
#Select columns from DB.table1 where col1 = (select col1 from DB.table2 limit 1);
#Select * from DB.tables3 where col1 in (select col1 from DB.table1) and col2 in
(select col2 from DB.table2)
#Question: Find out which vendors primarily sell fresh products and which don’t.
select
vendor_id,
vendor_name,
vendor_type,
if(lower(vendor_type) like '%fresh%','Freshly Produced','Not Freshly Produced') as
vendor_category
from farmers_market.vendor;
#with case
select
vendor_id,
vendor_name,
vendor_type,
CASE
WHEN lower(vendor_type) like '%fresh%' THEN 'Freshly Produce'
WHEN lower(vendor_type) like '%meat%' THEN 'Non Veg Stuff'
ELSE 'Not Fresh Produce'
END as vendor_category
from farmers_market.vendor;
##DCS
select *,
ifnull(product_size,"Not Available") as product_size,
ifnull(product_qty_type,"Not Available") as product_typr
from farmers_market.product;