24 lines
2.4 KiB
Text
24 lines
2.4 KiB
Text
|
<span class="hljs-keyword">SELECT</span> *
|
||
|
<span class="hljs-keyword">FROM</span> (
|
||
|
<span class="hljs-keyword">SELECT</span>
|
||
|
posts.col1 <span class="hljs-keyword">AS</span> emp_id,
|
||
|
posts.col2 <span class="hljs-keyword">AS</span> dept_id,
|
||
|
posts.col3 <span class="hljs-keyword">AS</span> posts,
|
||
|
<span class="hljs-keyword">DENSE_RANK</span>() <span class="hljs-keyword">OVER</span> post_ranking <span class="hljs-keyword">AS</span> <span class="hljs-keyword">rank</span>
|
||
|
<span class="hljs-keyword">FROM</span> <span class="hljs-keyword">VALUES</span>
|
||
|
(<span class="hljs-number">1</span>, <span class="hljs-number">1</span> ,<span class="hljs-number">100</span>),
|
||
|
(<span class="hljs-number">2</span>, <span class="hljs-number">1</span> ,<span class="hljs-number">50</span>),
|
||
|
(<span class="hljs-number">8</span>, <span class="hljs-number">1</span> ,<span class="hljs-number">250</span>),
|
||
|
(<span class="hljs-number">3</span>, <span class="hljs-number">2</span> ,<span class="hljs-number">200</span>),
|
||
|
(<span class="hljs-number">4</span>, <span class="hljs-number">2</span> ,<span class="hljs-number">300</span>),
|
||
|
(<span class="hljs-number">9</span>, <span class="hljs-number">2</span> ,<span class="hljs-number">1000</span>),
|
||
|
(<span class="hljs-number">5</span>, <span class="hljs-number">3</span> ,<span class="hljs-number">300</span>),
|
||
|
(<span class="hljs-number">6</span>, <span class="hljs-number">3</span> ,<span class="hljs-number">100</span>),
|
||
|
(<span class="hljs-number">7</span>, <span class="hljs-number">3</span> ,<span class="hljs-number">400</span>) <span class="hljs-keyword">AS</span> posts
|
||
|
<span class="hljs-keyword">WINDOW</span> post_ranking <span class="hljs-keyword">AS</span> (
|
||
|
<span class="hljs-keyword">PARTITION</span> <span class="hljs-keyword">BY</span> posts.col2
|
||
|
<span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> posts.col3 <span class="hljs-keyword">DESC</span>
|
||
|
<span class="hljs-keyword">ROWS</span> <span class="hljs-keyword">BETWEEN</span> <span class="hljs-keyword">UNBOUNDED</span> <span class="hljs-keyword">PRECEDING</span> <span class="hljs-keyword">AND</span> <span class="hljs-keyword">CURRENT</span> <span class="hljs-keyword">ROW</span>)
|
||
|
)
|
||
|
<span class="hljs-keyword">WHERE</span> <span class="hljs-keyword">rank</span> <= <span class="hljs-number">2</span>;
|