Select rows by index in Amazon Athena

Multi tool use
Multi tool use


Select rows by index in Amazon Athena



This is a very simple question but I can't seem to find documentation on it. How one would query rows by index (ie select the 10th through 20th row in a table)?



I know there's a row_numbers function but it doesn't seem to do what I want.


row_numbers





I think row_number is the way to go. What problems do you face when you try this approach?
– Piotr Findeisen
Jun 29 at 10:12


row_number





example SQL would be help to let us understand what you want to do and what's the actual results. row_number() is just one out 6 ranking functions
– shawnzhu
Jul 2 at 14:05


row_number()





I'm looking for something like SELECT* from table WHERE row_number() between 5 and 10. But this doesn't work in Athena.
– Ajjit Narayanan
Jul 2 at 14:28


SELECT* from table WHERE row_number() between 5 and 10




1 Answer
1



I seem to have found a roundabout and clunky way of doing this in Athena, so any better answers are welcome. This approach requires you have some numeric column in your table already, in this case named some_numeric_column:


some_numeric_column


SELECT some_numeric_column, row_num FROM (
SELECT some_numeric_column,
row_number() over (order by some_numeric_column) as row_num
FROM your_table
)
WHERE row_num between 100000 and 100010



To explain, you first select some numeric column in your data, then create a column (called row_num) of row numbers which is based on the order of your selected numeric column. Then you wrap that all in a select call because Athena doesn't support creating and then conditioning on the row_num column within a single call. If you don't wrap it in a second SELECT call Athena will spit out some errors about not finding a column named row_num.


SELECT


row_num






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

grdte94xpL3NMy9KMOQpZdlL2ukkD H,vLz8jxBJYQYRe4TEJ,rq1,XcfUo1bg,UhhrduTJoAw
E 99 AYkEX,I GaVTm sNRyrm kP eHi qPsk7Z3D qT8flzC1BquiNLW,GFJFwvhxbK,SukAV,HjPk ea8i0,C

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications