Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are given the following query, which shows the total sales for each staff member, for movies with either Boring or Lumberjack or New Orleans

You are given the following query, which shows the total sales for each staff member, for movies with either "Boring" or "Lumberjack"
or "New Orleans" in the movie name. Improve the query performance.
SELECT
s.staff_id,
CONCAT(s.first_name, '', s.last_name) AS staff_name,
SUM(p.amount) AS total_sales
FROM
staff s
LEFT OUTER JOIN
rental r ON s.staff_id = r.staff_id
LEFT OUTER JOIN
payment p ON r.rental_id = p.rental_id
LEFT OUTER JOIN
inventory i ON r.inventory_id = i.inventory_id
LEFT OUTER JOIN
film f ON i.film_id = f.film_id
WHERE
p.payment_date IS NOT NULL
AND f.description LIKE '%Boring%'
AND f.description LIKE '%Lumberjack%'
AND f.description LIKE '%New Orleans%'
GROUP BY
s.staff_id,
staff_name
ORDER BY
total_sales DESC;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago