我有一个包含该数据的表MOVIE。
MOVIE_ID MOVIE_TITLE CATEGORY SALES_AMT --------- ------------------------ --------------- ---------- M_0000004 The Boss Baby Animation 2000 M_0000006 Star Wars: The Last Jedi Science Fiction 3000 M_0000007 Get Out Horror 4000 M_0000008 Million Dollar Arm Action 2000 M_0000009 The Conjuring Horror 1000 M_0000012 The Dark Knight Action 3000
我需要根据热门电影数据SALES_AMT相对于CATEGORY
SALES_AMT
CATEGORY
所需的结果是这样的:
MOVIE_ID MOVIE_TITLE CATEGORY SALES_AMT --------- ------------------------ --------------- ---------- M_0000004 The Boss Baby Animation 2000 M_0000006 Star Wars: The Last Jedi Science Fiction 3000 M_0000007 Get Out Horror 4000 M_0000012 The Dark Knight Action 3000
如果使用GROUP_BY选项,则无法选择MOVIE_ID和MOVIE_TITLE
MOVIE_ID
MOVIE_TITLE
select CATEGORY, MAX(SALES_AMT) from MOVIE group by CATEGORY ;
尝试使用解析函数和子查询
select movie_id, movie_title, category, sales_amt from ( select movie_id, movie_title, category, sales_amt, row_number() over (partition by category order by sales_amt desc) r from movie ) where r = 1