Question: Description Problem 4 Write a query based on the vendor _ booth _ assignments table to display market _ date, vendor _ id , booth

Description
Problem 4
Write a query based on the vendor_booth_assignments table to display market_date, vendor_id, booth_number, and for each vendor on each market_date, the booth_number from their previous market_date (name it as previous_booth_number). Sort the results by market_date and then vendor_id.
query sql
F- enter your SQL code below:
SELECT
vba.market_date,
vba.vendor_id,
vba.booth_number,
COALESCE (prev_vba.booth_number, 'N/A') AS previous_booth_number
FROM
vendor_booth_assignments vba
LEFT JOIN (
SELECT
vendor_id,
market_date,
LAG (booth_number) OVER (PARTITION BY vendor_id ORDER BY market_date) AS booth_number
FROM
vendor_booth_assignments
prevvba ON vba.vendor_id = prev_vba.vendor_id
7 AND vba.market_date = prev_vba. market_date
ORDER BY
vba.market_date,
vba.vendor_id;
Description
Problem 5
Write a query to display market_date, product_name, and product_category_name, as well as a field that is quantity * original_price (name it as cost) and a field that splits cost into 10 tiles (name it as decile), with 10 being the highest 10% and 1 being the lowest 10%. Only include products with a product_category_name containing the word 'Fresh' and only during the month of September 2019('2019-09-01' to '2019-09-30'). Sort the results by market_date and then product_name.
Hint: Join the tables of product_category, product, and vendor_inventory; Use the NTILE().
query.sql
1-- enter your SQL code below:
SELECT
vi.market_date,
p.product_name,
pc.product_category_name,
vi. quantity * vi.original_price AS cost,
NTILE(10) OVER (ORDER BY vi.quantity * vi.original_price DESC) AS decile
FROM
vendor_inventory vi
JOIN
product p ON vi. product_id = p. product_id
JOIN
product_category pC ON p.product_category_id = pc.product_category_id
WHERE
pc.product_category_name LIKE '%Fresh%'-- Filter for product categories containing 'Fresh'
AND vi.market_date '2019-09-01'
AND vi.market_date '2019-09-30'-- Filter for September 2019
ORDER BY
vi.market_date,
p.product_name;
Description Problem 4 Write a query based on the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!