我需要创建一个查询,其中我只在oracle中选择前十名,我似乎无法做到正确。我读过有关使用排名但是到目前为止,我还没弄明白。
select col , count(col) from table_name group by col
答案 0 :(得分:2)
您可以使用另一个查询包装此查询,并使用rownum
伪列:
SELECT col, cnt
FROM (SELECT col , COUNT(col) AS cnt
FROM table_name
WHERE col IS NOT NULL
GROUP BY col
ORDER BY 2 DESC)
WHERE rownum <= 10