怎样在select中查找。
select a,b,c from table where...
怎样根据a.b.c的各自情况select出a.b.c的数据。
a.b.c是表中的数据,但不是fields。*****************table1
--userid
--username
--userdesc
*****************table2
--userparent
--userid
--usertype   (type:1=mother;2=father)
*****************根据userid查找出mother(userid),mother(username),father(userid),father(username).形成4个field.

解决方案 »

  1.   

    select muserid, musername,fuserid, fusername,m.userid
    from(
        select m.userid,m.username,f.userid,f.username
        from 
          (select b.userid as muserid,b.username as musername,a.userid from table2 a,table1 b where usertype=1 and a.userparent=b.userid) m ,
          (select d.userid as fuserid,d.username as fusername,c.userid from table2 c,table1 d where usertype=2 and c.userparent=d.userid) f
        where m.userid=f.userid
    )
    where userid=?
      

  2.   

    行的,
    select t1.userid as uid, (select ...) as father, (...) as mother,...
    from table1 t1, table2 t2
      

  3.   

    ①table1
     userid  username  userdesc
      001   張三
      002   李四
    ...
    ②table2
      userid  userparent usertype
      001   張母    1
      001   張父    2
    ...
    ③結果
      select mother(userid)???,decode(usertype,'1',userparent),
             father(userid)???,decode(usertype,'2',userparent) 
      from table1 a,table2 b
      where a.userid = b.userid
        and a.userid = '001'哥們欠条件、写不出。