我执行一个SQL:select ah.*,drc.type from view_all_house ah left join dc_relation_cunstom drc  on drc.assets_type=ah.houseType and drc.assets_id=ah.id的出来的效果是
id   houseType  c_type  type
 1      1          0      1
 2      2          0      1
 3      3          0      2
当时我想要c_type显示是type的值,怎么弄
id   houseType  c_type  type
 1      1          1      1
 2      2          1      1
 3      3          2      2

解决方案 »

  1.   

    select ah.id, ahhouseType, drc.type, drc.type
      from view_all_house ah
      left join dc_relation_cunstom drc on drc.assets_type = ah.houseType
                                       and drc.assets_id = ah.id
      

  2.   


    select ah.id, ah.houseType,drc.type c_type,drc.type from view_all_house ah left join dc_relation_cunstom drc  on drc.assets_type=ah.houseType and drc.assets_id=ah.id
      

  3.   

    有点我不明白,你想显示type 那为什么还要显示c_type干什么呢?直接显示
    id houseType  type
    这三列不就行了吗
      

  4.   


    应该我做JAVA,对象只会映射ah里的元素!
      

  5.   


    select ah.id,ah.houseType,decode(c_type,0,drc.type,c_type) c_type,
    drc.type 
    from view_all_house ah left join dc_relation_cunstom drc  on drc.assets_type=ah.houseType and drc.assets_id=ah.id
      

  6.   


    select ah.id,ah.houseType,drc.type c_type,drc.type from view_all_house ah left join dc_relation_cunstom drc  on drc.assets_type=ah.houseType and drc.assets_id=ah.id
      

  7.   

    不解,如果只能取到 ah 里的元素,那其它表的值就取不到了?
    ah 与其它表的连接查询,结果没法取到?如果取不到,上面的回答没一个可以用
    如果能取到,直接替换c_type 为 type 就行了
      

  8.   

    不解你的java是怎么写的,你如果是取同一个列会出错的话,两个列取不同的别名就可以了吧