需求:部门表bm:部门id,每月,每月盈利金额
求每个部门的每月盈利占当月总金额的比率。
hql实现
create table bm (
id String,
month int,
money int
)
row format delimited fields terminated by ','
location '/warehous/bm';
A 7 30
B 7 100
A 8 20
A 9 68
select a.id,a.month,a.money/b.sum from bm a
join
(
select month,sum(money) as sum from bm
group by month
) b
on a.month=b.month;
A 7 30 0.23076923076923078
B 7 100 0.7692307692307693
A 8 20 1.0
A 9 68 1.0
每个部门的每月盈利占当月总金额的比率hql实现
最新推荐文章于 2020-12-26 08:18:26 发布