简体   繁体   中英

Convert this excel formula so it can work on SQL?

So it's been 1 week and I can't seem to figure it out.

=IF(D8="","",(IF((OR(R8<-3000,R8>3000)),"Outlier", IF((AND(S8>=-50%,S8<=50%,T8>=-50%,T8<=50%)),"Matched", IF((OR(AB8<-50%,AB8>50%)),"Outlier","Matched")))))

Thank you!!

I tried doing it on my own but I got mad and deleted everything so I can't put any of what I did here haha

Assuming your column/field names are D, R, S, T and AB - from table #myTab

SELECT CASE 
  WHEN D = ',' AND (R < -3000 OR R > 3000) THEN 'Outlier'
  WHEN D = ',' AND (S >= -50 AND S <= 50 AND T >= -50 AND T <= 50) THEN 'Matched'
  WHEN D = ',' AND (AB < -50 OR AB > 50) THEN 'Outlier'
  WHEN D = ',' THEN 'Matched'
  ELSE NULL END
  AS Result
FROM #myTab;

Note this is written with the D = ',' so that each line stands alone - in case you want to modify it.

Otherwise, you can make the first check to be WHEN D <> ',' THEN NULL then remove the later checks on D.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM