select SUM(category)
from film_list
where title IN actors;
我被困了,我正在研究sakila数据库,而我正试图弄清楚电影类别中有55到65部电影。返回这些名称 类别和每个类别的电影数量,按电影数量排序。请问有什么想法吗?
答案 0 :(得分:1)
我认为你需要一个小组并且有
select category, count(*) as num_film
from film_list
group by category
having num_film BETWEEN 55 AND 65
order by num_fim
答案 1 :(得分:1)
试试这个
SELECT category, Count(*) AS FilmsCount
FROM Film_List
GROUP BY Category
HAVING Count(*) BETWEEN 55 AND 65
ORDER BY FilmsCount
答案 2 :(得分:0)
猜测:
SELECT category, COUNT(*) AS films_per_category
FROM film_list
GROUP BY category
HAVING COUNT(*) BETWEEN 55 AND 65
ORDER BY films_per_category
但是,如果您提供大纲架构和一些示例数据,那么就不会猜测。当然,我们不希望看到55行,但出于演示目的,5到6行之间可以正常工作。
答案 3 :(得分:0)
这称为子查询:
select sum(category)
from film_list
where title IN (SELECT title FROM actors);
答案 4 :(得分:0)
尝试此操作,它将回答以下查询: -查找包含55到65部电影的所有电影类别。返回这些名称 类别和每个类别的电影数量,按电影数量排序。
SELECT
category.name,
COUNT(fc.category_id) AS `Movies per Category`
FROM
film_category AS fc
JOIN
category ON fc.category_id = category.category_id
GROUP BY fc.category_id
HAVING `Movies per Category` BETWEEN 65 AND 75
ORDER BY `Movies per Category` DESC;
答案 5 :(得分:-2)
尝试使用Between运算符
SELECT category, COUNT(*) AS films_per_category
FROM film_list
ORDER BY films_per_category
HAVING COUNT(*) BETWEEN 55 AND 65