GROUPBY1
GROUPBY1
Find out which vendors primarily sell fresh products and which don’t. Add an
identifier column for the same.
vendor_id,
SELECT
vendor_name,
vendor_id,
vendor_type,
vendor_name,
CASE vendor_type,
WHEN lower(vendor_type) LIKE "%fresh%" IF(UPPER(vendor_type) LIKE "%FRESH%",
SELECT
customer_id,
market_date,
COUNT(*) AS num_orders
FROM `farmers_market.customer_purchases`
GROUP BY customer_id, market_date
ORDER BY market_date, customer_id
Calculate the total quantity purchased by each customer per market_date.
SELECT
customer_id,
market_date,
SUM(quantity) AS total_quantity
FROM `farmers_market.customer_purchases`
GROUP BY customer_id, market_date
ORDER BY market_date, customer_id
How many different kinds of products were purchased by each customer on each
market date?
SELECT
customer_id,
market_date,
COUNT(DISTINCT product_id) num_products
FROM `farmers_market.customer_purchases`
GROUP BY customer_id, market_date
ORDER BY market_date, customer_id