dimanche 17 juillet 2016

Hive QL Difference between two closest elements in a column

Let's say I have a very simple table like this:

ID: Integer
A    4
A    9
A    2
B    4 
B    7
B    3

And I want to groupBy(ID). What would be an appropriate query that tells me the minimum difference - like this

ID: MIN_DIF:
A    2
B    1

Simplicity of the query right now is more important than efficiency, but both the most basic and the most efficient query would be appreciated.

Sidenote: Finding the average distance would be a bonus, but I need min first

Aucun commentaire:

Enregistrer un commentaire