如何在 oracle sql 中使用 max on sum?
How to use max on sum in oracle sql?
我正在执行一项任务,但遇到了特定问题。我是 SQL 的新手,所以我正在联系这个平台寻求支持。下面是 2 tables。第一个是 Theatre_play_table,第二个是 Ticketsales table。
问题:列出所有 shows/plays 总销量最高的片名、导演和编剧。
Theatre_play_table
门票销售table
我已经粘贴了 table 的某些部分的屏幕截图。 ID 列中的两者 table 代表相同的信息。 Ticketsales table 中的最后一列是 Totalamount。
我试过以下查询;
Select theatre_play.title, theatre_play.director, theatre_play.writer, sum(totalamount)
来自 theatre_play,总销售额
其中 theatre_play.id = totalsales.id
按 theatre_play.title、theatre_play.director、Theatre_play.writer 分组
按总和(总金额)降序排列
仅获取前 3 行;
当数据量很大时,上述方法就没有用了。我想应用 max(sum(totalamount)) 但 oracle 抛出了一个错误。
谁能帮我解决这个问题?
如果我没理解错的话,问题是获取三个最高值?
然后尝试这样的事情:
select * from (
Select dpro.title, dpro.director, dpro.writer, sum(fth.totalamount)
from dpro
join fth on dpro.id = fth.id
group by dpro.title, dpro.director, dpro.writer
order by sum(totalamount) desc )
where rownum <=3
我正在执行一项任务,但遇到了特定问题。我是 SQL 的新手,所以我正在联系这个平台寻求支持。下面是 2 tables。第一个是 Theatre_play_table,第二个是 Ticketsales table。 问题:列出所有 shows/plays 总销量最高的片名、导演和编剧。
Theatre_play_table
门票销售table
我已经粘贴了 table 的某些部分的屏幕截图。 ID 列中的两者 table 代表相同的信息。 Ticketsales table 中的最后一列是 Totalamount。
我试过以下查询; Select theatre_play.title, theatre_play.director, theatre_play.writer, sum(totalamount) 来自 theatre_play,总销售额 其中 theatre_play.id = totalsales.id 按 theatre_play.title、theatre_play.director、Theatre_play.writer 分组 按总和(总金额)降序排列 仅获取前 3 行;
当数据量很大时,上述方法就没有用了。我想应用 max(sum(totalamount)) 但 oracle 抛出了一个错误。
谁能帮我解决这个问题?
如果我没理解错的话,问题是获取三个最高值? 然后尝试这样的事情:
select * from (
Select dpro.title, dpro.director, dpro.writer, sum(fth.totalamount)
from dpro
join fth on dpro.id = fth.id
group by dpro.title, dpro.director, dpro.writer
order by sum(totalamount) desc )
where rownum <=3