title: Presto window function get only top 10 records of each group
body: <p>I am using <strong>window function</strong> on <strong>Presto</strong> to group each partition the result is returning as extected but I want to grab only top 10 records of each partition. But If I apply LIMIT 10 then it returns only 10 rows among all partition not individual partition. <strong>Note:</strong> I've seen similar question on <a href="https://stackoverflow.com/questions/16303343/t-sql-to-find-top-10-records-for-each-group">here</a> but it seems complicated. Is there any easy way to fix this?</p>
  <p><strong>Query Used:</strong></p>
  <pre><code>WITH TOP_USERS AS (
   SELECT NAME, UNAME, DATE,
    ROW_NUMBER() OVER (PARTITION BY NAME,UNAME ORDER BY DATE ASC) AS RN FROM TABLE_NAME 
  )
  SELECT * FROM TOP_USERS WHERE RN=1  ORDER BY NAME LIMIT 100
  </code></pre>
  <p><strong>Current Result:</strong></p>
  <pre><code>NAME    UNAME             DATE                  RN
  BBIG    StockHighArmy   2021-01-07 01:07:04.000 1
  BCII    VinnytheLEFT    2021-01-07 09:54:35.000 1
  BEGI    RadioSilentplay 2021-01-07 10:38:45.000 1
  BEGI    aheadsupotc 2021-01-07 10:42:51.000     1
  BETRF   greg_lechuga    2021-01-07 09:23:55.000 1
  BIEI    trade_dr    2021-01-07 08:57:10.000     1
  BIEI    ThornLeafArtist 2021-01-07 09:20:37.000 1
  BIEI    Vegas_Whoa  2021-01-07 00:57:12.000     1
  BIEI    trader_bearded  2021-01-07 08:13:53.000 1
  BITCF   OTCBullRider    2021-01-07 10:29:11.000 1
  BKLLF   OddStockTrader  2021-01-07 10:04:45.000 1
  BLDV    A10_Vet 2021-01-07 10:33:19.000         1
  BLPG    NedGreen5   2021-01-07 09:54:07.000     1
  BLPG    ThebuyG 2021-01-07 09:38:16.000         1
  BLPG    StockRocket1    2021-01-07 09:20:20.000 1
  BLPG    aheadsupotc 2021-01-07 09:57:30.000     1
  BLPG    mando2250   2021-01-07 01:39:52.000     1
  BLPG    crabbermike 2021-01-07 08:28:08.000     1
  BLPG    Scottspg1033    2021-01-07 06:20:08.000 1
  BLPG    thestocks7889   2021-01-07 00:24:06.000 1
  BLPG    koba19822012    2021-01-07 09:28:15.000 1
  BLPG    StockStar319    2021-01-07 09:32:11.000 1
  BLPG    rrr1sr  2021-01-07 09:16:25.000         1
  BLPG    BodaciousTrade  2021-01-07 09:52:49.000 1
  BLPG    TheChaseGroup1  2021-01-07 06:23:58.000 1
  BLPG    rj34704726  2021-01-07 00:57:22.000     1
  BLPG    claydeath1  2021-01-07 09:22:35.000     1
  BLPG    Chivitotrader   2021-01-07 09:38:08.000 1
  </code></pre>
  <p><strong>Expected Result:</strong> (<strong>SEE BLPG has only 10 rows</strong>)</p>
  <pre><code>NAME    UNAME             DATE                  RN
  BBIG    StockHighArmy   2021-01-07 01:07:04.000 1
  BCII    VinnytheLEFT    2021-01-07 09:54:35.000 1
  BEGI    RadioSilentplay 2021-01-07 10:38:45.000 1
  BEGI    aheadsupotc 2021-01-07 10:42:51.000     1
  BETRF   greg_lechuga    2021-01-07 09:23:55.000 1
  BIEI    trade_dr    2021-01-07 08:57:10.000     1
  BIEI    ThornLeafArtist 2021-01-07 09:20:37.000 1
  BIEI    Vegas_Whoa  2021-01-07 00:57:12.000     1
  BIEI    trader_bearded  2021-01-07 08:13:53.000 1
  BITCF   OTCBullRider    2021-01-07 10:29:11.000 1
  BKLLF   OddStockTrader  2021-01-07 10:04:45.000 1
  BLDV    A10_Vet 2021-01-07 10:33:19.000         1
  BLPG    NedGreen5   2021-01-07 09:54:07.000     1
  BLPG    ThebuyG 2021-01-07 09:38:16.000         1
  BLPG    StockRocket1    2021-01-07 09:20:20.000 1
  BLPG    aheadsupotc 2021-01-07 09:57:30.000     1
  BLPG    mando2250   2021-01-07 01:39:52.000     1
  BLPG    crabbermike 2021-01-07 08:28:08.000     1
  BLPG    Scottspg1033    2021-01-07 06:20:08.000 1
  BLPG    thestocks7889   2021-01-07 00:24:06.000 1
  BLPG    koba19822012    2021-01-07 09:28:15.000 1
  BLPG    StockStar319    2021-01-07 09:32:11.000 1
  BLPG    rrr1sr  2021-01-07 09:16:25.000         1
  BLPG    BodaciousTrade  2021-01-07 09:52:49.000 1
  BLPG    TheChaseGroup1  2021-01-07 06:23:58.000 1
  </code></pre>