案件 [英] case

查看:84
本文介绍了案件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助解决流动的问题,谢谢

Please help for the flowing question, Thanks

我需要找出最终余额=信用 - ( T1 + T2 + T3)。但是, 

t1-仅退出 当st1 = 2且st2 = 1或(st1 = 1且st2 = 1且st3 = 1) 

t2-仅在 时退出st1 = 2或(st1 = 1且  st3 = 1)

t3-仅在 时退出st1 = 2或(st1 = 1且  st3 = 1)

在下面的示例中,t1不存在,因此最终余额=信用 - (t2 + t3)= 5000-(1000+ 1500)

I need to find out the final balance = credit -(t1+t2+t3). However, 
t1- only exits  when st1=2 and st2=1 or (st1=1 and st2=1 and st3=1) 
t2- only exits when  st1=2 or (st1=1 and  st3=1)
t3- only exits when  st1=2 or (st1=1 and  st3=1)
In the example below, t1 is not exist, so the final balance = credit -(t2+t3) =5000-(1000+1500)

推荐答案

SELECT final_balance = credit - (

  CASE WHEN st1 = 2 AND st2 = 1 OR( st1 = 1 AND st2 = 1 AND st3 = 1)那么t1 ELSE 0 END +


  CASE WHEN st1 = 2 OR(st1 = 1 AND st3 = 1)那么t2 ELSE 0结束+

 案例当st1 = 2或(st1 = 1 AND st3 = 1)那么t3 ELSE 0 END



来自Your_Table
SELECT final_balance = credit - (
 CASE WHEN st1=2 AND st2=1 OR (st1=1 AND st2=1 AND st3=1) THEN t1 ELSE 0 END +
 CASE WHEN st1=2 OR (st1=1 AND st3=1) THEN t2 ELSE 0 END +
 CASE WHEN st1=2 OR (st1=1 AND st3=1) THEN t3 ELSE 0 END
)
FROM Your_Table


这篇关于案件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆