java吧 关注:1,220,371贴子:12,671,540
  • 2回复贴,共1

求帮忙写一个oracle语句

只看楼主收藏回复

我有两个表,一个是xy_history表,一个是xy_dwinfo,要求是查询一列表里面的日期减去当前日期要大于30天的数据,输出的字段有xy_dwinfo的d2,d21,xy_history的d2,d3,d5 typyid,xy_history的xyid对应xy_dwinfo的d21,求大神帮忙,可私聊加qq


IP属地:上海来自Android客户端1楼2017-05-05 23:54回复
    select dh.d2,dh.d3,dh.d5,dh.typeid, (select d2 from xy_dwinfo where d21=dh.xyid) dwd2,(select d21 from xy_dwinfo where d21=dh.xyid) d21 from dw_history dh,
    (select xyid,MAX(to_date(d3,'yyyy/mm/dd')) md from dw_history group by xyid) mh where dh.xyid=mh.xyid and (to_date(dh.d3,'yyyy/mm/dd'))=mh.md and (to_date(dh.d3,'yyyy/mm/dd')-SYSDATE)>30 order by d21


    IP属地:上海来自Android客户端2楼2017-05-05 23:55
    收起回复