oracle的rownum與having用法 去除重複 在重複情況用rownum

來源:互聯網
上載者:User

一般來說,大家會用rownum,也就是偽列來指定要顯示多條資料,

比如

select linename from aced  where rownum<3 

但是,大家注意,如果取出來的資料有重複資料,用rownum是達不了你要的效果的。比如你要取5條資料,其中四條是重複,那你最後只能得到兩條。


那該腫麼辦呢,解決辦法如下:


SELECT
*
FROM
(
SELECT
PROJECT_LISTING.VARIETY_NAME
FROM
PROJECT_LISTING
WHERE
PROJECT_LISTING.VARIETY_NAME IS NOT NULL
GROUP BY
PROJECT_LISTING.VARIETY_NAME
HAVING
COUNT (*) = 1
)
WHERE
ROWNUM <= 5


這樣就可以了。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.