【发布时间】:2018-10-11 02:43:47
【问题描述】:
我有多个表格,分别是艺术家、专辑、曲目、invoice_items、invoices、customers。
我在下面写了sql查询:
select country, artistid, name, revenue from
(select t6.country, t1.artistid, t1.name, sum(t4.quantity*t4.unitprice) as revenue
from artists
t1 inner join albums t2
inner join tracks t3
inner join invoice_items t4
inner join invoices t5
inner join customers t6 on t1.artistid=t2.artistid
and t2.albumid=t3.albumid
and t3.trackid=t4.trackid
and t4.invoiceid=t5.invoiceid
and t5.customerid=t6.customerid
group by t6.country, t1.artistid
);
查询的输出:
预期输出: 每个国家/地区按收入排序的前 3 名艺术家。因为我需要分别获得阿根廷、澳大利亚、巴西、美国的前三名。
【问题讨论】: