前两个值就是比如imputedate字段排在记录前面的两个记录

解决方案 »

  1.   

    在具体一点就是我想查itemid=3的inputdate排在前面的两个记录和itemid=6的inputdate排在前面的两个记录
      

  2.   

    是不是要查询表中以ITEMID分组的INPUTDATE较早的前两条记录啊!?
      

  3.   

    是不是要查询表中以ITEMID分组的INPUTDATE较早的前两条记录啊!?是
      

  4.   

    select * from (select * from where INPUTDATE<(select INPUTDATE from table where itemid=3) order by INPUTDATE desc) a where rownum<=2;
      

  5.   

    select * from (select * from where INPUTDATE<(select INPUTDATE from table where itemid=3) order by INPUTDATE desc) a where rownum<=2
    union all
    select * from (select * from where INPUTDATE<(select INPUTDATE from table where itemid=5) order by INPUTDATE desc) a where rownum<=2
      

  6.   

    还是不行
    报错信息ORA-00903: invalid table name光标指向第二个*后面的from上
      

  7.   

    粗心大意!!!select * from (select * from table where INPUTDATE<(select INPUTDATE from table where itemid=3) order by INPUTDATE desc) a where rownum<=2
    union all
    select * from (select * from table where INPUTDATE<(select INPUTDATE from table where itemid=5) order by INPUTDATE desc) a where rownum<=2把相应的表名替换
      

  8.   

    楼上的还是不行
    报ORA-01427: single-row subquery returns more than one row
      

  9.   

    select * from (select * from (select * from testone where itemid<3 order by itemid desc) where rownum<=2) union all (select * from (select * from testone where itemid<=5 order by itemid desc) where rownum<=2);你把相应的表名替换吧,我试过了,可以的
      

  10.   

    select * from (select * from table_name where itemid=3 order by inputdate desc) where rownum<3
    union 
    select * from (select * from table_name where itemid=5 order by inputdate desc) where rownum<3将表名table_name替换了在用,可能中间有敲错的,自己纠错吧
      

  11.   

    明白了,select INPUTDATE from table where itemid=3
    与 select INPUTDATE from table where itemid=5在表内已超过一条记录,当然报错select ITEMID,CONTENT,CHINESE from table group by ITEMID,CONTENT,CHINESE hvaing count(itemid)<=2 order by INPUTDATE desc;请楼主测试!
      

  12.   

    明白了,select INPUTDATE from table where itemid=3
    与 select INPUTDATE from table where itemid=5在表内已超过一条记录,当然报错select ITEMID,CONTENT,CHINESE from table group by ITEMID,CONTENT,CHINESE hvaing count(itemid)<=2 order by INPUTDATE desc;不知是否你的意思?
      

  13.   

    select * from (select * from table_name where itemid=3 order by inputdate desc) where rownum<3
    union 
    select * from (select * from table_name where itemid=5 order by inputdate desc) where rownum<3将表名table_name替换了在用,可能中间有敲错的,自己纠错吧
      

  14.   

    还是不行beckhambobo(beckham) 不过我已经解决了,谢谢你
    ORA-00933: SQL command not properly ended