不确定为什么这不起作用......好像> = b是一个布尔表达式。 RDMS抱怨“> = 3”说“缺少关键字”。我遵循了语法here
这有效:
WHEN count(movie_num) 3 THEN 'Most Popular'
这不是:
WHEN count(movie_num) >=3 THEN 'Most Popular'
可能遗漏了一些明显的东西,所以我很抱歉,如果是这样的话。
完整查询
select movie_genre as "Movie Genre",
count(movie_num) as "Number of Movies",
CASE count(movie_num)
WHEN count(movie_num) >=3 THEN 'Most Popular'
WHEN count(movie_num) >= 2 THEN 'Popular'
ELSE 'Normal' END AS "Popularity Rating"
from movie
group by movie_genre
order by count(movie_num) desc;
答案 0 :(得分:1)
试试这个,
更改 CASE(movie_num)当计数(movie_num) 到 CASE WHEN count(movie_num)
select movie_genre as "Movie Genre",
count(movie_num) as "Number of Movies",
CASE WHEN count(movie_num) >=3 THEN 'Most Popular'
WHEN count(movie_num) >= 2 THEN 'Popular'
ELSE 'Normal' END AS "Popularity Rating"
from movie
group by movie_genre
order by count(movie_num) desc;
答案 1 :(得分:1)
根据您的条件,您可以重写它以使用simple-case expression:
select movie_genre as "Movie Genre",
count(movie_num) as "Number of Movies",
CASE count(movie_num)
WHEN 0 THEN 'Normal'
WHEN 1 THEN 'Normal'
WHEN 2 THEN 'Popular'
ELSE 'Most Popular'
END AS "Popularity Rating"
from movie
group by movie_genre
order by count(movie_num) desc;