表格如下:
得出結果如下:
求精簡的SQL語句
with a as(
select rank() over (partition by 商店 order by 商店,sum(價錢) desc) as rowid,
商店,sum(價錢) as 價錢和,備注 from 產品 group by 備注,商店),
b as(
select 商店,價錢和,備注 from a where rowid = 1),
c as(
select 商店,sum(價錢和) as 賣出價錢和 from a group by 商店)
select c.商店,c.賣出價錢和,b.備注 as 賣出價錢最高貨物,b.價錢和 as 賣出最高價格貨物價格之和
from c inner join b on c.商店 = b.商店