Guest User

Untitled

a guest
Aug 22nd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. +----+------+
  2. | id | col1 |
  3. +----+------+
  4. | 1 | abc |
  5. | 2 | def |
  6. | 3 | ghi |
  7. | 4 | jkl |
  8. | 5 | mno |
  9. +----+------+
  10.  
  11. select
  12. id,
  13. col1,
  14. row_number() over(order by col1 desc) as row_num
  15. from #table
  16.  
  17. with NumberedRows as
  18. (
  19. select id, col1,
  20. row_number() over(order by col1 desc) as row_num
  21. from #table
  22. )
  23. select id, col1, row_num
  24. from NumberedRows
  25. where col1 = 'jkl'
Add Comment
Please, Sign In to add comment