有三个表
要创建一个view
如果A表中的  a  字段值为 0
则让   A表  id  字段等于 B表的id  
如果A表中的  a  字段值为 1
则让   A表  id  字段等于 C表的id

解决方案 »

  1.   

    a字段即表示男女     男女的信息不同  所以分别存在  B表   C表里   
      

  2.   

    如果b,c表的字段是一样的话,可以这样来
    select a.*, b.* from a, b where a.a=0 and a.id=b.idunion select a.*, c.* from a, c where a.a=1 and a.id=c.id
      

  3.   

    4楼的用union all更合适
    如果a.a没加索引,并且a记录数很多
    也可以这样:
    select a.*,
    decode(a.a, 0, b.x, 1, c.x),
    decode(a.a, 0, b.x, 1, c.x),
    decode(a.a, 0, b.x, 1, c.x),
    ...
    from a, b, c where a.id=b.id(+) and a.id=c.id(+)
      

  4.   

    这个用case或者decode 很容易解决
    case 写法更容易被系统接受,因为它与ansi兼容,符合SQL/92标准
    select A.*,
      case A.a when 0 then b.X
               else c.X
               end as X
    from A left join B using(id)
         left join C using(id)
      

  5.   

    decode函數.這個是oracle特有的函數.
      

  6.   

    只要保证两个select 的内容一致就可以了,union all 貌似也可以