请高手指点多表查询问题

QingT26 2011-09-22 05:04:28
我写的语句如下:
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 为记录全国各城市申请业务的用户信息,这个表中有点特殊用户名是有加域名的,就像我的的邮箱地址一样,如:test0001@163.com,status为是否处理用户申请的标识,0为未处理,1为已处理。
我现在不知道申请的用户是属于哪个城市,我想结合用户信息表与城市表找出这个申请业务的用户是哪个城市的。
上面这条语句没有报错但查不出数据,单独执行前面和后面的语句是可以查出数据来,请高手指点下是我的语句有问题还是方法不对?
...全文
90 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
QingT26 2011-09-23
  • 打赏
  • 举报
回复
现在数据终于查出来了,两位说的都有道理,结合三楼的语句再去掉空格就可以了。
语句帖出来希望后面会有人用得到。
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)||'%')
QingT26 2011-09-22
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 jimmylin040 的回复:]

试试用exists看看

SQL code

select a.username,b.name
from userinfo_portal a,
area_info b
where a.id = b.id(+)
and exists(select 'X'
from applyvoipnumberinfo c
……
[/Quote]

用exists我昨天就试过了一样的找不到数据,你这个语句也一样。呵呵!
QingT26 2011-09-22
  • 打赏
  • 举报
回复
[Quote=引用楼主 qingt26 的回复:]
我写的语句如下:
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);
我先介绍三张表:
use……
[/Quote]

这个就是带域名的用户名,因为用户表中的用户名和域名都是分名的,也就是说是两个字段,在这里比较时就得截取一下。
jimmylin040 2011-09-22
  • 打赏
  • 举报
回复
上面些少了点东西


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)||'%')
jimmylin040 2011-09-22
  • 打赏
  • 举报
回复
试试用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))
luoyoumou 2011-09-22
  • 打赏
  • 举报
回复
-- userinfo_portal表的username 字段的数据类型是什么?


-- 注意:如果userinfo_portal表的username 字段的数据类型是char()类型的话,当数据长度不够时,
-- Oracle会自动在其后面补空格,此时你去跟 表 applyvoipnumberinfo 中 wimaxno 字段 的前8个字符去比较,就可能不匹配(userinfo_portal表的username 字段,可能因为后面有空格)
luoyoumou 2011-09-22
  • 打赏
  • 举报
回复
-- 表 applyvoipnumberinfo 中 wimaxno 字段是做什么滴?
-- 确定只取前8个字符去与 userinfo_portal表的username 字段比较么?

3,499

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧