Dynamically choose one of two columns based on a third column

This question already has an answer here:

  • How do I perform an IF…THEN in an SQL SELECT? 22 answers

  • 如果您尝试选择A(如果C = T或B)(如果C = F),则可以仅使用一个Case语句

    Select (Case When C.val = TRUE Then A.val Else B.Val END) AS D
    From Table
    

    你可以使用CASE语法。

    SELECT CASE WHEN C.val = 'T' THEN A.val ELSE B.val END as yourField
    
    链接地址: http://www.djcxy.com/p/94344.html

    上一篇: 如果还有条件在SQL中

    下一篇: 基于第三列动态选择两列中的一列