利用Sakila数据库练习SQL查询

avatar
作者
猴君
阅读量:0

  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; 

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!