2 Filtering - Lecture - Queries
2 Filtering - Lecture - Queries
SELECT *
FROM `farmers_market.product`
WHERE product_category_id = 1
Print all the purchases made by customer id 4, sorted by market date.
SELECT *
FROM `farmers_market.customer_purchases`
WHERE customer_id = 4
ORDER BY market_date
Get all the products and info with id between 3 and 8(not inclusive)
and of product with id 10.
SELECT *
FROM `farmers_market.product`
WHERE (product_id > 3 AND product_id < 8) OR product_id = 10
Find out what booths were assigned to vendor_id 3 on or before
2019-04-20
SELECT *
FROM `farmers_market.vba`
WHERE vendor_id = 3 AND market_date <= "2019-04-20"
Find out the booth assignments for vendor 7 for any date between April 3,
2019 and May 16, 2019, including the extreme dates.
SELECT *
FROM `farmers_market.vba`
WHERE vendor_id = 7 AND (market_date BETWEEN "2019-04-20" AND "2019-05-18")
Return a list of customers with selected last names [Diaz,
Wilson, Edwards]
SELECT *
FROM `farmers_market.customer`
WHERE LOWER(customer_last_name) IN ("diaz", "wilson", "edwards")
You want to get data about a customer whom you knew as “Jerry” but you
aren’t sure how they are listed in the DB, “Jerry”, Jeremy or Jeremiah
SELECT *
FROM `farmers_market.customer`
WHERE LOWER(customer_first_name) LIKE "jer%"
Find all the products that don’t have size mentioned corresponding to
their records.
SELECT *
FROM product
TRIM(product_size) = ""
Extract all the purchase related information for the dates when it rained.
SELECT *
FROM `farmers_market.customer_purchases`
WHERE market_date IN (SELECT
market_date
FROM `farmers_market.mdi`
WHERE market_rain_flag = 1)
List down all the products(with their info) where product category names
contains fresh in it.
SELECT *
FROM `farmers_market.product`
WHERE product_category_id IN (SELECT
product_category_id
FROM `farmers_market.product_category`
WHERE LOWER(product_category_name) LIKE "%fresh%")