用SQL语句书写,当A>B时,选择A,否则B,当B>C时,选择B,否则C

解决方案 »

  1.   

    declare @t table(A int ,B int,C int)
    insert @t
    select 1,5,3 union
    select 4,0,2 union
    select 6,2,9select Val=(case when A>B then A when B>C then B else C end)
    from @tVal
    -----------
    5
    4
    6(3 行受影响)
      

  2.   

    按照LZ的描述:
    select case when A>B then A 
           when B>C then B else C res
    from tb
    不过感觉这个逻辑不严密。
      

  3.   

    --用SQL语句书写,当A>B时,选择A,否则B,当B>C时,选择B,否则C
    select 
    case when A>B then A else B  END as '列值1',
    case when B>c then B else C end as '列值'
    from tb
      

  4.   


    select case when a > b then a else b end,
           case when b > c then b else c end
    from tb
      

  5.   

    declare @t table(A int ,B int,C int)
    insert @t
    select 1,5,3 union
    select 4,0,2 union
    select 6,2,9select Val=(case when A>B then A when B>C then B else C end)
    from @t