它要求获得工资,但从一些状态实体(健康和afp)打折。例如,这些实体有不同的折扣,而ppl将有不同的Afp和Health,所有这些都是混合的。
和
我怎样才能拿到薪水,却又不多呢?
IF (afp=1)
IF (health=1)
IF (health=2)
IF (health=3)
IF (afp=2)
IF (health=1)
IF (health=2)
IF (health=3)以此类推,有什么办法可以避免这样的情况吗?希望你们能帮我,thnks
发布于 2020-04-20 13:22:06
您可以使用case表达式:
select (case when afp = 1 and health = 1 then 0.05
when afp = 1 and health = 2 then 0.10
when afp = 1 and health = 3 then 0.15
when afp = 2 and health = 1 then 0.07
when afp = 2 and health = 2 then 0.12
when afp = 2 and health = 3 then 0.18
end) as discount或者引用表,您可以动态构建:
select t.*, v.discount
from t left join
(values (1, 1, 0.05), (1, 2, 0.10), . . .
) v(afp, health, discount)
on t.afp = v.afp and t.health = v.health发布于 2020-04-20 13:38:38
另一个选择是choose()
示例
Select Discount = choose(aft,.05,.10,.15) + choose(health,.02,.02,.03)
From YourTablehttps://stackoverflow.com/questions/61323478
复制相似问题