请教各位  这样的句子有什么问题 
select * from tablename where type=1 order by time desc union all select * from tablename where type=2 order by time desc

解决方案 »

  1.   

    这是报的错 ORA-00933: SQL command not properly ended
      

  2.   

    select * from tablename where type=1 union all select * from tablename where type=2 order by time desc;少;号
      

  3.   

    还有,order by需要最后进行。不能分别进行
      

  4.   

    还有,order by需要最后进行。不能分别进行
      
    ====================================================================================
    我就是问这个呀  最后写order by 还问什么呀现在情况是这样的  一个表里有N中类型的记录 type=?    我要把每种记录按时间顺序取前5条出来  sql 如下:select * from tabelname where type=0 and rownum<6 order by time desc union all select * from tabelname where type=1 and rownum<6 order by time desc union all select * from tabelname where type=2 and rownum<6 order by time desc union all select * from tabelname where type=3 and rownum<6 order by time desc 
    该怎么办呀
      

  5.   

    select *
    from (select * from tablename where type=1 order by time desc)
     union all 
    select *
    from (select * from tablename where type=2 order by time desc)
    order by time desc差不多可以
      

  6.   

    select * from (select * from tabelname where type=0 and rownum<6 order by time desc) a 
    union all select * from (select * from tabelname where type=1 and rownum<6 order by time desc) b 
    union all select * from (select * from tabelname where type=2 and rownum<6 order by time desc) c 
    union all select * from (select * from tabelname where type=3 and rownum<6 order by time desc) d这样应该可以达到你的要求吧
      

  7.   

    select * from tablename where type in (1,2) order by type,time desc
      

  8.   

    要找前5条:
    select * from (select *,row_number() over(partition by type order by time desc) rank from tablename ) a where a.rank<=5
      

  9.   

    和我今天遇到的问题一模一样,呵呵。参考一我的吧:
    select * from (
     select * from (select zxzx_id, zxzx_sort,zxzx_title,to_char(zxzx_add_date,'yyyy-mm-dd hh24:mi')zxzx_add_date FROM zxzx where zxzx_sort='2' order by zxzx_add_date desc) where rownum <3 
     union select * from (select zxzx_id, zxzx_sort,zxzx_title,to_char(zxzx_add_date,'yyyy-mm-dd hh24:mi')zxzx_add_date FROM zxzx where  zxzx_sort='3'  order by zxzx_add_date desc) where rownum <4
     union select * from (select zxzx_id, zxzx_sort,zxzx_title,to_char(zxzx_add_date,'yyyy-mm-dd hh24:mi')zxzx_add_date FROM zxzx where  zxzx_sort='4'  order by zxzx_add_date desc) where rownum <4 
     ) order by to_number(zxzx_sort) desc,zxzx_add_date desc
      

  10.   

    其实就是嵌套查询的问题,楼主这样排序,呵呵,结果集怎么知道UNION中两个结果集如何排序?
      

  11.   

    hem(何明) 正解, 用分析函数解决问题
      

  12.   


    select  * from(
    select   *   from   tablename   where   type=1 
    union all
    select   *   from   tablename   where   type=2 
    ) rr order by time desc
      

  13.   

    union时候只允许在最后面指定排序