Hive 中特定列的区别

发布于 2024-12-04 08:18:24 字数 385 浏览 4 评论 0原文

我正在运行 Hive 071。 我有一个表,有多行,具有相同的列值。

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

我想让 x 列唯一,并删除具有相同 x 值的行;

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

或者

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

两者都很好。

由于 unique 仅适用于 Hive 中的整行,因此我找不到方法来做到这一点。

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

 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;

 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 row in Hive, I couldn't find a way to do it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

随梦而飞# 2024-12-11 08:18:24

您可以使用 unique 关键字:

SELECT DISTINCT x FROM table

You can use the distinct keyword:

SELECT DISTINCT x FROM table
昔梦 2024-12-11 08:18:24

尝试以下查询来获取结果:

select Ax , Ay from (select x , y ,rank() over (partition by x order by y) as returned from testingg)A 其中ranked=1;

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;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文