我是刘刘啊 2017-06-25 05:58 采纳率: 66.7%
浏览 855
已采纳

oracle数据库中minus和外键问题的求解

请各位大神帮帮我 ,问题是这样的
首先,一下我的sql语句
select * from customer_info cus join customer_type type on cus.type_id=type.type_id join customer_condition con on cus.condition_id=con.condition_id join customer_source source on cus.source_id=source.source_id join user_info u on u.user_id=cus.user_id where 1=1 and rownum <= 5
minus
select * from customer_info cus join customer_type type on cus.type_id=type.type_id join customer_condition con on cus.condition_id=con.condition_id join customer_source source on cus.source_id=source.source_id join user_info u on u.user_id=cus.user_id where 1=1 and rownum < 1
第一句和最后一句唯一的不同就是最后的where语句那里
这是执行第一句的结果
这是执行最后一行的结果
其中外键有图片说明
以下是一起执行的结果图片说明
结果typeId等有外键关联的列的列名变了,请问这是为什么,怎么恢复原来的样子?

  • 写回答

2条回答 默认 最新

  • huangwenkangz 2017-06-26 08:07
    关注

    第二句废话rownum < 1 那只能等于0 所以第二句是没有数据的
    select * from customer_info cus join customer_type type on cus.type_id=type.type_id join customer_condition con on cus.condition_id=con.condition_id join customer_source source on cus.source_id=source.source_id join user_info u on u.user_id=cus.user_id where 1=1 and rownum <= 5
    改成
    select cus.*
    from customer_info cus,
    customer_type type ,
    customer_condition con,
    customer_source source,
    user_info u
    where cus.type_id=type.type_id(+)

    and cus.condition_id=con.condition_id(+)

    and cus.source_id=source.source_id(+)
    and u.user_id(+)=cus.user_id
    and rownum <= 5
    至于列名变了,感觉这个列名有点像rowid,要先查这个列名是哪里来的

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条