0% found this document useful (0 votes)
3 views11 pages

2 Filtering - Lecture - Queries

The document contains a series of SQL queries designed to extract specific data from a farmers market database. Queries include filtering products by category, retrieving customer purchases, and finding vendor booth assignments within certain date ranges. Additional queries focus on customer names, product sizes, and conditions such as weather-related purchases.
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)
3 views11 pages

2 Filtering - Lecture - Queries

The document contains a series of SQL queries designed to extract specific data from a farmers market database. Queries include filtering products by category, retrieving customer purchases, and finding vendor booth assignments within certain date ranges. Additional queries focus on customer names, product sizes, and conditions such as weather-related purchases.
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/ 11

Filtering - Lecture Queries

Extract all product names that belong to product category id 1

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

WHERE product_size IS NULL OR

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%")

You might also like