title: Cleaner/more efficient way to pull top 10% only
body: <p>I'm creating a leaderboard to return just the top 10% revenue streams this quarter.  I've hacked together a solution with analytic functions but I feel like there's a simpler way.</p>
  
  <p>The main fields are stream_ID, stream_rev, quarter, and timestamp (the table contains revenue whenever it happens, which can be multiple times a day)</p>
  
  <p>Here's what I've done:</p>
  
  <pre><code>SELECT stream_ID,
         rev,
         rev_rank
         FROM(
         SELECT stream_ID,
                count(distinct stream_ID) OVER () as total_streams,
                sum(stream_rev) as rev,
                rank() OVER (ORDER BY sum(stream_rev) desc) AS rev_rank
          FROM mastertable
          WHERE quarter = "2019-Q4"
          GROUP BY stream_ID
          )
  WHERE rev_rank/total_streams &lt;= .1
  </code></pre>