Это просто с мощными ORACLE ANALYTICAL FUNCTIONS
Ниже приведен максимальный доход для каждого pub_id
.
select pub_id,REV from
(
select pub_id, (sales*price) as REV,
max(sales*price) over (partition by pub_id order by 1) as MAX
from titles
)
where REV=MAX
Если вы хотите определитьpub_id
с максимальной выручкой:
select * from
(
select pub_id,REV from
(
select pub_id, (sales*price) as REV,
max(sales*price) over (partition by pub_id order by 1) as MAX
from titles
)
where REV=MAX order by MAX desc
)
where rownum<2