这样写为什么报错?select t.usercode,
       (case when substr('3600',0,2)= '36' then
         (select u.unit from dic_unit u where u.unitid = t.usercode)
         else
         ( select s.username from T_USER s where s.loginname=t.usercode)
          end) as sender
  from t_sms t;求大侠

解决方案 »

  1.   

    select t.usercode,
           (case
             when substr('3600', 0, 2) = '36' then
              (select u.unit from dic_unit u where u.unitid = t.usercode)   --这里是表达式,不能是子查询啊
             else
              (select s.username from T_USER s where s.loginname = t.usercode) --这里是表达式,不能是子查询啊
           end) as sender
      from t_sms t;
      

  2.   

    select t1.usercode,
           case
             when substr('3600', 0, 2) = '36' then
              sender1
             else
              sender2
           end sender (select t.usercode,
                        (select u.unit
                           from dic_unit u
                          where u.unitid = t.usercode) sender1,
                        (select s.username
                           from T_USER s
                          where s.loginname = t.usercode) sender2
                   from t_sms t) t1
    改成上面这样试试
      

  3.   


    还是不行,u.unit 的字段定义是varchar(200) ,s.username字段定义的是varchar(50)是不是这个原因呢?
      

  4.   

    select t.usercode,
           (case when substr('3600',1,2)= '36' then u.unit
            else s.username end) as sender
      from t_sms t,dic_unit u,T_USER s
      where t.unitid=u.unitid and t.usercode=s.loginname;
      

  5.   

    select u.unit from dic_unit u where u.unitid = t.usercode 看看是不是有多条数据