Oracle数据库中先按时间(年过滤)在按销量降序在取前十条的数据的sql怎么写
降序取前十个
select * from (select * from 表名 order by 销量 desc ) where rownum<='10'
过滤时间在降序
SELECT * FROM 表名 where to_char(时间,'YYYY')='${sta}'order by 销量 desc
怎么把这两种两种sql结合起来,做到先过滤时间在降序,在取前十
select * from (select * from 表名 where to_char(时间,'YYYY')='${sta}' order by 销量 desc ) where rownum<='10'
这样试试。
select * from (select ROWNUM AS RN,a.* from 表名 a where to_char(a.时间,'YYYY')='${sta}' order by a.销量 desc ) b where b.RN<=10