select rownum message_id,send_to_p,titles,to_char(send_time,'yyyy-mm-dd hh24:mi') from (select message_id,send_to_p,titles,to_char(send_time,'yyyy-mm-dd hh24:mi') from t4012 where send_from='xxx' order by send_time desc)我在这里查询日期格式的字段,怎么报send_time标识无效了?????把send_time去掉就可以查询出来

解决方案 »

  1.   

    --你的子查询不加入别名,改为select rownum message_id,send_to_p,titles,to_char(send_time,'yyyy-mm-dd hh24:mi') as send_time
      from (select message_id,send_to_p,titles,to_char(send_time,'yyyy-mm-dd hh24:mi') as send_time
            from t4012 where send_from='xxx' order by send_time desc) t
      

  2.   

    select rownum message_id,send_to_p,titles,to_char(send_time,'yyyy-mm-dd hh24:mi') from (select message_id,send_to_p,titles,to_char(send_time,'yyyy-mm-dd hh24:mi') as  send_time  from t4012 where send_from='xxx' order by send_time desc)
      

  3.   

    别名, 内sql to_char(send_time,'yyyy-mm-dd hh24:mi')  取得的字段名为 to_char(send_time,'yyyy-mm-dd hh24:mi') 
      

  4.   

    当然有这个字段拉,是报第1个send_time标识无效
      

  5.   

    send_time字段是什么数据类型的?
      

  6.   

    select rownum message_id,send_to_p,titles,
    to_char(send_time,'yyyy-mm-dd hh24:mi')
    from (
      select message_id,send_to_p,titles,
      to_char(send_time,'yyyy-mm-dd hh24:mi')
      from t4012
      where send_from='xxx'
      order by send_time desc

    改为:
    select rownum message_id,send_to_p,titles,
    send_time --使用子查询里的别名字段,已经转换过了,不用再转换,to_char(send_time,'yyyy-mm-dd hh24:mi')
    from (
      select message_id,send_to_p,titles,
      to_char(send_time,'yyyy-mm-dd hh24:mi') as send_time --这里要定义别名
      from t4012
      where send_from='xxx'
      order by send_time desc

      

  7.   


    取别名select rownum message_id,send_to_p,titles,to_char(send_time,'yyyy-mm-dd hh24:mi') from (select message_id,send_to_p,titles,to_char(send_time,'yyyy-mm-dd hh24:mi') send_time from t4012 where send_from='xxx' order by send_time desc)
      

  8.   

    我知道你的意图了 不过好像可以简单点:
     SELECT ROW_NUMBER() OVER(ORDER BY SEND_TIME DESC) MESSAGE_ID,
      SEND_TO_P,
      TITLES,
      --TO_CHAR(SEND_TIME, 'yyyy-mm-dd hh24:mi') 这个干嘛转来做什么的?
      SEND_TIME
    FROM T4012
      WHERE SEND_FROM = 'xxx'