Skip to content

jecastrom/lab-sql-join

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 

Repository files navigation

Lab SQL Join

Instructions:

1. List number of films per category.

Answer:

SELECT
    c.`name` AS film_category,
    count(fc.film_id) AS number_of_films
FROM
    category c
    INNER JOIN film_category AS fc ON c.category_id = fc.category_id
GROUP BY
    1
ORDER BY
    2 DESC;
150024562 12a517f9 c6dd 43c3 9cf2 7f384d5e783c

2. Display the first and last names, as well as the address, of each staff member.

Answer:

SELECT
    concat((last_name), ', ', (first_name)) AS staff_member_name,
    address
FROM
    staff s
    INNER JOIN address a ON s.address_id = a.address_id
ORDER BY
    1;
150027923 55014b9d e104 48ea 9fda c7edaf66cef1

3. Display the total amount rung up by each staff member in August of 2005.

Answer:

SELECT
    concat((last_name), ', ', (first_name)) AS staff_member_name,
    sum(amount) AS total_sales_august_2005
FROM
    staff s
    INNER JOIN payment p ON s.staff_id = p.staff_id
WHERE
    monthname(payment_date) = 'August'
    AND year(payment_date) = 2005
GROUP BY
    1;
150031435 de71ed54 4cba 4501 b0f8 d87d8b8d0fe2

4. List each film and the number of actors who are listed for that film.

Answer:

SELECT
    f.title,
    count(fa.actor_id) AS number_of_actors
FROM
    film f
    INNER JOIN film_actor fa ON f.film_id = fa.film_id
GROUP BY
    f.film_id
ORDER BY
    2 DESC
LIMIT
    10;
150034018 7bf998ff fd62 4371 b50f b8a3bc2a1030

5. Using the tables payment and customer and the JOIN command

  • list the total paid by each customer.

  • List the customers alphabetically by last name.

Answer:

SELECT
    concat((last_name), ', ', (first_name)) AS customer_name,
    sum(amount) AS amount_total_paid
FROM
    customer c
    INNER JOIN payment p ON c.customer_id = p.customer_id
GROUP BY
    p.customer_id
ORDER BY
    1
LIMIT
    10;
150035387 dab91b17 7014 4a02 a6b4 3f1bcc45c90d


Releases

No releases published

Packages

No packages published