fuliding 2016-06-13 05:35 采纳率: 0%
浏览 2347

select 字段里嵌套select 用法问题

select o.username,
o.uagent,
o.cscode,
o.product,
(SELECT min(time.createTime)
FROM (select t.createtime
from dataintegration t
where t.username = o.username

union all
select t.user_create_time
from diuser t
where t.user_name = o.username) time) createTime
from dataintegration o

            里面会报o.username无效,到底是什么问题?怎么解决?o表里一定有username字段,拜托大家
  • 写回答

1条回答

  • 哥特卷子猫 2016-06-13 06:12
    关注

    select t.createtime
    from dataintegration t
    where t.username = o.username

    union all
    select t.user_create_time
    from diuser t
    where t.user_name = o.username
    这段是最底层(第三层),它的外面是自定义的TIME表(第二层),而O表在TIME表外面(第一层),where条件不能跨层取。
    如果你一定想这么写的话,把O表放到最底层去,或者
    select o.username,
    o.uagent,
    o.cscode,
    o.product,
    min( createTime)
    from(
    select o.username,
    o.uagent,
    o.cscode,
    o.product,
    (select t.createtime
    from dataintegration t
    where t.username = o.username

           union all
           select t.user_create_time
             from diuser t
           where t.user_name = o.username) createTime
    

    from dataintegration o
    )

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图