您的位置:首页 > 其它

相同物料不同供应商显示时合并总价格

2012-07-13 16:32 375 查看

1.原始数据

MAT    EXT QUANTITY    PEIBI   PRICE
a   x   1            1  10
b   z   1            1  10
c   F   1            0.3    10
c   H   1            0.7    10
d   I   1            0.1    10
d   J   1            0.1    10
d   x   1            0.8    10

2.分区查询后的数据

MAT  EXT QUANTITY    PEIBI   PRICE   SUMV    RANKS   CNT
a   x   1       1   10  1   1   1
b   z   1       1   10  1   1   1
c   F   1       0.3 10  1   1   2
c   H   1       0.7 10  1   2   2
d   I   1       0.1 10  1   1   3
d   J   1       0.1 10  1   2   3
d   x   1       0.8 10  1   3   3

3.对物料MAT相同、供应商EXT不同按匹配、价格、数量求和

sumv=图号M供应商1的peibi*price*quantity+图号M供应2的peibi*price*quantity+……

物料  供应商 配比  数量  价格  sum
M1  E1  0.7 1   10  20
M1  E2  0.3 1   10  //这里合并了
M2  E2  1   1   20  20

4.SQL

with a as
(
select 'a' mat,'x' ext,1 quantity,1.00 peibi, 10 price from dual
union all
select 'b' mat,'z' ext,1 quantity,1.00 peibi, 10 price from dual
union all
select 'c' mat,'H' ext,1 quantity,0.70 peibi, 10 price from dual
union all
select 'c' mat,'F' ext,1 quantity,0.30 peibi, 10 price from dual
union all
select 'd' mat,'I' ext,1 quantity,0.10 peibi, 10 price from dual
union all
select 'd' mat,'J' ext,1 quantity,0.10 peibi, 10 price from dual
union all
select 'd' mat,'x' ext,1 quantity,0.80 peibi, 10 price from dual
)
select mat,ext,quantity,peibi,price,
sum(quantity*peibi) over(partition by mat ) sumV,
rank() over(partition by mat order by mat,ext) ranks,
count(*) over(partition by mat  ) cnt from a order by mat,ext


What's this?!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐