Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

window-function.txt 544B

1234567891011121314151617181920212223
  1. SELECT *
  2. FROM (
  3. SELECT
  4. posts.col1 AS emp_id,
  5. posts.col2 AS dept_id,
  6. posts.col3 AS posts,
  7. DENSE_RANK() OVER post_ranking AS rank
  8. FROM VALUES
  9. (1, 1 ,100),
  10. (2, 1 ,50),
  11. (8, 1 ,250),
  12. (3, 2 ,200),
  13. (4, 2 ,300),
  14. (9, 2 ,1000),
  15. (5, 3 ,300),
  16. (6, 3 ,100),
  17. (7, 3 ,400) AS posts
  18. WINDOW post_ranking AS (
  19. PARTITION BY posts.col2
  20. ORDER BY posts.col3 DESC
  21. ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
  22. )
  23. WHERE rank <= 2;