select
d.部门,
d.人,
sum(case
when a.销售价格>c.成本价格
then b.奖励系数A*a.销售数量+(a.销售价格-c.成本价格)*b.额外奖励系数
when a.销售价格<c.成本价格
then b.奖励系数B*a.销售数量
when a.销售价格=c.成本价格
then b.奖励系数A*a.销售数量
end)
from
a,b,c,d
where
a.销售单号=d.销售单号
and
a.X=c.X
and
b.部门 = d.部门
group by
d.部门,d.人
d.部门,
d.人,
sum(case
when a.销售价格>c.成本价格
then b.奖励系数A*a.销售数量+(a.销售价格-c.成本价格)*b.额外奖励系数
when a.销售价格<c.成本价格
then b.奖励系数B*a.销售数量
when a.销售价格=c.成本价格
then b.奖励系数A*a.销售数量
end)
from
a,b,c,d
where
a.销售单号=d.销售单号
and
a.X=c.X
and
b.部门 = d.部门
group by
d.部门,d.人
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货