这是数据库设计:
CREATE TYPE album_type AS OBJECT(
album_title VARCHAR(99),
price NUMBER,
tracks track_table
)
CREATE TYPE track_type AS OBJECT(
song_title VARCHAR(99),
download_count INTEGER )
这是我的SQL,我想使用max()函数来选择下载次数最多的歌曲:
select al.album_title,tt.song_title, max(tt.download_count)
from album al, table(al.tracks) tt where al.title='XXX'
group by album_title, song_title
但输出有多个记录,这意味着它没有选择最大数字,我在哪里出错了sql语句?
答案 0 :(得分:0)
你可能想要更像的东西:
select album_title,song_title from
( select al.album_title,tt.song_title,
row_number() over (tt.download_count desc) as rn
from album al, table(al.tracks) tt where al.title='XXX'
)
where rn=1;