请教各位 这样的句子有什么问题
select * from tablename where type=1 order by time desc union all select * from tablename where type=2 order by time desc
select * from tablename where type=1 order by time desc union all select * from tablename where type=2 order by time desc
====================================================================================
我就是问这个呀 最后写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
该怎么办呀
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差不多可以
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这样应该可以达到你的要求吧
select * from (select *,row_number() over(partition by type order by time desc) rank from tablename ) a where a.rank<=5
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
select * from(
select * from tablename where type=1
union all
select * from tablename where type=2
) rr order by time desc