开发者

Distinct on specific column in Hive

开发者 https://www.devze.com 2023-04-04 07:51 出处:网络
I am running Hive 071 I have a table, with mulitple rows, with the same column value e.g. x | y | ---------

I am running Hive 071 I have a table, with mulitple rows, with the same column value e.g.

 x | y |
---------
 1 | 2 |
 1 | 3 |
 1 | 4 |
 2 | 2 |
 3 | 2 |
 3 | 1 |

I want to have the x column unique, and remove rows that have the same x val e.g.

 x | y |
---------
 1 | 2 |
 2 | 2 |
 3 | 2 |

or

 x | y |
---------
 1 | 4 |
 2 | 2 |
 3 | 1 |

are both good开发者_运维技巧 as distinct works only on the whole rs in hive, I couldn't find a way to do it

help please Tx


You can use the distinct keyword:

SELECT DISTINCT x FROM table


try following query to get result :

select A.x , A.y from (select x , y , rank() over ( partition by x order by y) as ranked from testingg)A where ranked=1;

0

精彩评论

暂无评论...
验证码 换一张
取 消