我写的语句如下:
select a.username,b.name from userinfo_portal a left join area_info b on a.id = b.id
where a.username in (select substr(wimaxno,1,8) from applyvoipnumberinfo where status=0);
我先介绍三张表:
userinfo_portal 为用户基本信息表,里面有城市的id,
area_info 为城市信息表里面只在id与城市名
applyvoipnumberinfo 为记录全国各城市申请业务的用户信息,这个表中有点特殊用户名是有加域名的,就像我的的邮箱地址一样,如:[email protected],status为是否处理用户申请的标识,0为未处理,1为已处理。
我现在不知道申请的用户是属于哪个城市,我想结合用户信息表与城市表找出这个申请业务的用户是哪个城市的。
上面这条语句没有报错但查不出数据,单独执行前面和后面的语句是可以查出数据来,请高手指点下是我的语句有问题还是方法不对?

解决方案 »

  1.   

    -- 表 applyvoipnumberinfo 中 wimaxno 字段是做什么滴?
    -- 确定只取前8个字符去与 userinfo_portal表的username 字段比较么?
      

  2.   

    -- userinfo_portal表的username 字段的数据类型是什么?
    -- 注意:如果userinfo_portal表的username 字段的数据类型是char()类型的话,当数据长度不够时,
    --       Oracle会自动在其后面补空格,此时你去跟 表 applyvoipnumberinfo 中 wimaxno 字段 的前8个字符去比较,就可能不匹配(userinfo_portal表的username 字段,可能因为后面有空格)
      

  3.   

    试试用exists看看
    select a.username,b.name 
      from userinfo_portal a,
           area_info b
     where a.id = b.id(+)
       and exists(select 'X'
                    from applyvoipnumberinfo c
                   where c.status=0
                     and upper(c.wimaxno) like upper(a.username))
      

  4.   

    上面些少了点东西
    select a.username,b.name 
      from userinfo_portal a,
           area_info b
     where a.id = b.id(+)
       and exists(select 'X'
                    from applyvoipnumberinfo c
                   where c.status=0
                     and upper(c.wimaxno) like upper(a.username)||'%')
      

  5.   


    用exists我昨天就试过了一样的找不到数据,你这个语句也一样。呵呵!
      

  6.   

    现在数据终于查出来了,两位说的都有道理,结合三楼的语句再去掉空格就可以了。
    语句帖出来希望后面会有人用得到。
    select a.username,b.name 
      from userinfo_portal a,
           area_info b
     where a.id = b.id(+)
       and exists(select substr(c.wimaxno,1,8)
                    from applyvoipnumberinfo c
                   where c.status=0
                     and c.wimaxno like trim(a.username)||'%')