大家看看这句sql语句有问题吗?

computerclass 2006-12-07 01:34:07
现有两个表,t_corp_user 和 t_co_user,表t_corp_user中有一个用户(字段reg_sim)对应多个管理员(sq_co_sim),反之也一样,表sq_co_sim中有一个操作员(reg_sim)对应一个管理员(login_sim),但一个管理员对应多个操作员。用户和操作员没有直接的对应关系。
用户---管理员---操作员
已知   用户(10023718700)和另一个有可能为管理员或操作员(10003710700),我想看看这个用户是不是属于这个管理员或操作员。
!!如太麻烦请直接看下面的语句
select id,reg_sim from t_corp_user
where reg_sim='10023718700' and (sq_co_sim='10003710700' or '10003710700' in (select reg_sim from t_co_user where login_sim in (select sq_co_sim from t_corp_user where reg_sim='10023718700')))
...全文
134 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
tianyacao007 2006-12-07
  • 打赏
  • 举报
回复
你得逻辑上可能没有问题,但是写的可能比较烦,还有这样一个sql中用到一个表两次,已经两个表有同样的列名需要对表起别名,并表明该列属于那张表!你看我写的这个是否可以!?献丑了
select tc.id,tc.reg_sim from t_corp_user tc
where tc.reg_sim='10023718700'
and (tc.sq_co_sim='10003710700'
or exists (select null
from t_co_user tcop,t_corp_user tcor
where tcop.login_sim = tcor.sq_co_sim
and tcor.reg_sim = '10023718700'
and tcop.reg_sim = '10003710700'))
tgm78 2006-12-07
  • 打赏
  • 举报
回复
where reg_sim='10023718700' and (sq_co_sim='10003710700' or '10003710700' in

有问题。


where reg_sim='10023718700' and sq_co_sim='10003710700' or sq_co_sim='10003710700' or sq_co_sim in (

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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