请教各位,我想查询(比如,字段create_date) 2011-12-09 7点到8点的前10条 和 9点到10点的前10条 等等,这个S
请教各位,我想查询(比如,字段create_date) 2011-12-09 7点到8点的前10条 和 9点到10点的前10条 等等,这个SQL怎么写?
请教各位,如果我想查询一个时间字段的 2011-12-09 号的 7点到8点的前10条 、 9点到10点的前10条 、11点到12点的前10条 等等,总共30条,这个SQL咋写?
[解决办法]
select t.*,t.rownum from tablename t where time >= '2011-12-09 07%' and time <= '2011-12-09 08%' and t.rownum<=10
UNION ALL
select t.*,t.rownum from tablename t where time >= '2011-12-09 09%' and time <= '2011-12-09 10%' and t.rownum<=10
UNION ALL
select t.*,t.rownum from tablename t where time >= '2011-12-09 11%' and time <= '2011-12-09 12%' and t.rownum<=10
[解决办法]
- SQL code
select * from (select row_number() over (partition by trunc(time_data,'hh') order by time_data) rn,t.* from twhere sign(time_data-to_date('2009-12-09 07','yyyy-mm-dd hh24'))+sign(time_data-to_date('2009-12-09 08','yyyy-mm-dd hh24'))=0 or sign(time_data-to_date('2009-12-09 09','yyyy-mm-dd hh24'))+sign(time_data-to_date('2009-12-09 10','yyyy-mm-dd hh24'))=0 or ...)t2where t2.rn <=10 