SQL技巧之分组求和
时间:2021-07-01 10:21:17
帮助过:10人阅读
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.商店
SQL技巧之分组求和
标签: