Lab 2
Lab 2
show schemas; Question 2: Write a SQL statement that returns all of the actors where the first _name contains the letter 'v'. Include your results. SELECT * FROM actor WHERE first_name LIKE 'V%'; Question 3: How many distinct ratings exist in the film table? Write a SQL state ment that returns the ratings, and the count of films for each rating. There are five distinct ratings in the film table. SELECT rating, COUNT(rating) FROM film GROUP BY rating; Question 4: Write a SQL statement that returns all films whose rating is PG or l ess, and which are shorter than 100 minutes. Include your results. SELECT rating, length FROM film WHERE (rating = 'PG' OR rating = "G") AND length < 100; Question 5: Write a SQL statement that returns the count of films in the film t able with a replacement cost greater than ten dollars. Include your results. SELECT COUNT(replacement_cost) FROM film WHERE replacement_cost > 10; Question 6: Write a SQL statement that returns all films that start with the let ter 'q'. No row should appear more than once in the output. Include your results . List the following information in your output: film id film title film rating film category (name) GROUPfilm, SELECT FROM WHERE title BY film_id, film_id; category LIKEtitle, 'q%' rating, name Question 7: Write a SQL statement that returns all the actors whose last name starts with 'a ', together with the count of films that they participated in by film category a nd rating. No row should appear more than once in the output. Order your results by film category (name), actor first name, then by film title. Include your res ults. List the following information in your output: actor last name
actor first name film category (name) film rating film count SELECT actor.last_name, actor.first_name, category.name, film.rating, film_actor FROM actor, .film_id WHERE actor.actor_id category,=film, film_actor.actor_id film_actor AND film.film_id = film_actor.film_id GROUP ORDER AND actor.last_name BY category.name, actor.actor_id LIKE actor.first_name, 'a%' film.title; Question 8: Write a SQL statement that lists the following information for all customers who se customer id is a multiple of 23. No row should appear more than once in the o utput. Order your results by customer last name, then by customer first name. In clude your results. List the following information in your output: customer id customer last name customer first name customer email average rental amount most recent rental date most recent return date SELECT customer.customer_id, customer.last_name, customer.first_name, customer.e mail,customer, FROM WHERE AVG(payment.amount), customer.customer_id payment, rental rental.rental_date, = payment.customer_id rental.return_date AND customer.customer_id = rent al.customer_id AND GROUP ORDER customer.customer_id BY customer.last_name, customer.customer_id AND rental.rental_id % 23customer.first_name; = 0 = payment.rental_id Question 9: Write a SQL statement that gives the customer counts by country, city, and posta l code. No row should appear more than once. Order your results by country, then city, then postal code. Include your results. List the following information in your output: country id country city id city postal code customer count SELECT country.country_id, country, city.city_id, city, postal_code, COUNT(custo FROM country, mer_id) WHERE country.country_id city, address, = city.country_id customer AND city.city_id = address.city_id AN D address.address_id GROUP ORDER BY country.country_id, country.country_id = customer.address_id city.city_id, address.postal_code; Question 10: Write a SQL statement that gives the total count of films in inventory by city. No row should appear more than once. Order your results by city name. Include yo ur results. List the following information in your output: city id city name film count SELECT country.country_id, city.city_id country, city, postal_code, COUNT(paymen FROMaddress.address_id t.customer_id) WHERE AND country, country.country_id city, address, = customer.address_id = city.country_id customer, payment AND AND address.city_id payment.customer_id = city.city_id = customer. GROUP BY city.city_id; customer_id ORDER country.country_id