温馨提示×

利用Sakila数据库练习SQL查询

小樊
94
2024-08-06 21:25:14
栏目: 云计算

  1. 查询所有电影的数量
SELECT COUNT(*) AS total_movies
FROM film;
  1. 查询所有电影的平均租金
SELECT AVG(rental_rate) AS avg_rental_rate
FROM film;
  1. 查询电影库存大于10的电影名称和库存量
SELECT title, inventory_id
FROM film
WHERE inventory_id > 10;
  1. 查询租借记录中每个客户借阅电影的总数量
SELECT customer_id, COUNT(*) AS total_rentals
FROM rental
GROUP BY customer_id;
  1. 查询最近一个月内租借次数最多的电影
SELECT film_id, COUNT(*) AS total_rentals
FROM rental
WHERE rental_date >= DATE_SUB(NOW(), INTERVAL 1 MONTH)
GROUP BY film_id
ORDER BY total_rentals DESC
LIMIT 1;

0