0% found this document useful (0 votes)
11 views2 pages

Mutlti

The document contains SQL queries that retrieve customer data from tables including customers who purchased on a specific date, customers who were deleted but had purchases, new or deleted customers, and total purchases by product category.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Mutlti

The document contains SQL queries that retrieve customer data from tables including customers who purchased on a specific date, customers who were deleted but had purchases, new or deleted customers, and total purchases by product category.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

SELECT C.customer_id, C.

customer_first_name

FROM `farmers_market.customer` C
LEFT JOIN `farmers_market.customer_purchases` CP

ON C.customer_id = CP.customer_id

WHERE CP.customer_id IS NULL

#Get a list of customers' zip codes for customers who made a purchase on 2019-04-06

SELECT DISTINCT C.customer_zip


FROM `farmers_market.customer` C
INNER JOIN `farmers_market.customer_purchases` CP
ON C.customer_id = CP.customer_id
WHERE CP.market_date = '2019-04-06'

##Customers who's account got deleted but they had A Purchase

Select cp.customer_id
from `farmers_market.customer_purchases` cp
left join `farmers_market.customer` c
on c.customer_id = cp.customer_id
where c.customer_id is null

##Customer who are new or customer who deleted the account

Select c.customer_id as new_cust,


cp.customer_id as deleted
from `farmers_market.customer_purchases` cp
full join `farmers_market.customer` c
on c.customer_id = cp.customer_id
where cp.customer_id is null
or c.customer_id is null

Select cp.customer_id, 'deleted cust' as type


from `farmers_market.customer_purchases` cp
left join `farmers_market.customer` c
on c.customer_id = cp.customer_id
where c.customer_id is null

union distinct

Select c.customer_id, 'new_cust' as type


from `farmers_market.customer_purchases` cp
Right join `farmers_market.customer` c
on c.customer_id = cp.customer_id
where cp.customer_id is null

Select cp.product_id, p.product_name, c.product_category_name, sum(cp.quantity) as


total

From `farmers_market.customer_purchases` cp
inner join `farmers_market.product` p
on p.product_id =cp.product_id

inner join `farmers_market.product_category` c


on c.product_category_id = p.product_category_id
where product_category_name like'%Fresh%'
group by 1,2,3

You might also like