After this, I’ll show you a sample.SELECT * FROM ( SELECT *, rank() over (PARTITION BY category_id ORDER BY quantity DESC) as rank FROM sample_table ) a WHERE rank < n;
I’ll insert test data to new table.1 a book1 100 2 b fashion1 10 3 a book2 1000 4 c food1 1 5 c food2 10 6 b fashion2 100 7 d medicine1 100 8 b fashion3 1 9 b fashion4 10 10 b fashion5 1 11 c food3 100 12 a book3 10 13 a book4 1
$ hive use test; CREATE TABLE test_item_order_data( item_id bigint, genre_id string, item_name string, quantity bigint ) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'; LOAD DATA LOCAL INPATH "/path/to/test data/test.dat" OVERWRITE INTO TABLE test_item_order_data; SELECT * FROM test_item_order_data; 1 a book1 100 2 b fashion1 10 3 a book2 1000 4 c food1 1 5 c food2 10 6 b fashion2 100 7 d medicine1 100 8 b fashion3 1 9 b fashion4 10 10 b fashion5 1 11 c food3 100 12 a book3 10 13 a book4 1
As you can see the result, when there are 2 2nd items, 3rd item should be rank 4.set hive.execution.engine=tez; SELECT *, rank() over (PARTITION BY genre_id ORDER BY quantity DESC) as rank FROM test_item_order_data; 3 a book2 1000 1 1 a book1 100 2 12 a book3 10 3 13 a book4 1 4 6 b fashion2 100 1 9 b fashion4 10 2 2 b fashion1 10 2 8 b fashion3 1 4 10 b fashion5 1 4 11 c food3 100 1 5 c food2 10 2 4 c food1 1 3 7 d medicine1 100 1 SELECT item_id, genre_id, item_name, quantity FROM ( SELECT *, rank() over (PARTITION BY genre_id ORDER BY quantity DESC) as rank FROM test_item_order_data ) io WHERE io.rank < 3; 3 a book2 1000 1 a book1 100 6 b fashion2 100 9 b fashion4 10 2 b fashion1 10 11 c food3 100 5 c food2 10 7 d medicine1 100
Streamlit is a …
I bought M5Stac…