SQL Q&A
SQL Q&A
SQL Q&A
total amount that the customer has paid along with date, customer id, vendor_id, qty, cost per qty
and the total amt.?
select market_date, customer_id, vendor_id, quantity,
cost_to_customer_per_qty,round((quantity*cost_to_customer_per_qty),2) as Total_amt from
`farmers_market.customer_purchases`
order by Total_amt desc;
#Question2: We want to merge each customer’s name into a single column that contains the first
name, then a space, and then the last name.
#Question3: In a customer’s full_name, we want the first_name to be in upper case followed by the
last_name as it is.
select concat(Upper(customer_first_name), ' ', customer_last_name) as customer_full_name from
`farmers_market.customer`;
#Question4: Extract all the product names that are part of product category 1
select * from `farmers_market.product`
where product_category_id = 1;
#Question5: Print a report of everything the customer_id 4 has ever purchased at the market,
sorted by date. Add total_amt column as well for each purchase.
#Question6: Get all the product info for products with id between 3 and 8 (not inclusive) and of
products with id 10.
#Question7: Find the booth assignments for vendor_id 7 for all dates between April 3, 2019 and
May 16, 2019, including the 2 dates.
#Question8: Return a list of customers with the following last names: [Diaz,Edwards, Wilson]
#Question9: We want to merge each customer’s name into a single column that contains the first
name, then a space, and then the last name. In the last name, just display the first character of the
last name. Write the first name part in the capitalized format. Put the last name part in capital.
#Question10: You want to get data about a customer you knew as Jerry but you are not sure if they
are listed as Jeremy or Jeremiah or Jerry. Get all customers whose name has “er” in between their
first names.
#Question11: Find all of the products from the product table which don’t have sizes mentioned.
#Question13: List down all the product details where product_category_name contains “Fresh” in
it.
#Question14: Find out which vendors primarily sell fresh products and which don’t.
select *, case when (lower(vendor_type) like '%fresh%') then '1' else '0' end as fresh_flag from
`farmers_market.vendor`;
#Question15: Put the total cost to customer purchases into bins of -under $5.00,$5.00–
$9.99,$10.00–$19.99, or $20.00 and over.
select *,
case
when(total_cost < 5) then 'under5'
when(total_cost between 5 and 9.99) then 'under10'
when(total_cost between 10 and 19.99) then 'under20'
else 'over20'
end as bins
from (select *,round(quantity*cost_to_customer_per_qty,2) as total_cost from
`farmers_market.customer_purchases`);
#Question16: Get a list of customers' zip codes for customers who made a purchase on 2019-04-
06.
#Question17: List all the products along with their product category name.
#Question18: Find out the customers who are new to the market.--> the customers who don't have
any purchase history::
#Question19: Find out the customers who are either new to the market or have deleted their
account from the market.
#Question20 :: Recommend new countries to the users which they have not visited yet
#Question21 :: Correlated Subquery:: find all employees with a salary higher than their average
departmental salary.
#Question 24 :: Calculate the total quantity purchased by each customer per market_date.
#Question 25 :: Calculate the total quantity purchased by each customer per market_date and sort
the output for every market date based on the quantity values (higher quantity value comes first)
#Question 26 :: How many different kinds of products were purchased by each customer on each
market date?