Advertisement
elena1234

dense_rank and where with subquery in MySQL

Feb 12th, 2023
1,332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.24 KB | Source Code | 0 0
  1. -- 1. We want to reward out users who have been around the longest. Find the 5 oldest users.
  2.  
  3. SELECT * FROM
  4. (
  5. SELECT *,
  6. DENSE_RANK() OVER(ORDER BY created_at) AS time_dense_rank
  7. FROM users
  8. ) AS A
  9. WHERE time_dense_rank BETWEEN 1 AND 5;
  10.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement