我想在ORDER BY
条件之前写一个WHERE
子句,因为我需要将结果截断为10,但我需要先按字母顺序排序。
我知道你不能在ORDER BY
之前加WHERE
所以我该怎么做?
我需要做以下事情:
SELECT *
FROM myTable
ORDER BY TOP10
WHERE ROWNUM <=10
答案 0 :(得分:14)
您可以使用此
的内联视图SELECT *
FROM (
SELECT *
FROM myTable
ORDER BY TOP10) T
WHERE ROWNUM <=10
答案 1 :(得分:4)
SELECT *
FROM (SELECT * FROM myTable RANK() OVER (ORDER BY TOP10) rank)
WHERE rank <= 10;
有关详情,请参阅this
编辑:感谢Wolf纠正:
select * from (select mt.*, rank() over (order by top10) rank from mytable mt)
WHERE rank <= 10