如何过滤雪花内的一对行
我有一张桌子,就像:
ID | 宠物 | 国家 |
---|---|---|
45 | 狗 | 我们 |
72 | 狗 | CA |
15 | 猫 | CA |
36 | 猫 | 美国 |
21 | 蛇 | fr |
12 | 蛇 | 在 |
20 | 猪 | 中 |
14 | 猪 | 14猪 |
33 | 马 | iq |
90 | 马 | ID |
行配对/分组基于匹配宠物。我只想选择包括美国在内的对。基本上,每对国家的价值都将使美国和另一个国家/一个价值之一是美国。例如,结果表将是
ID | 宠物 | 国家 |
---|---|---|
45 | 狗 | US |
72 | 狗 | CA |
15 | 猫 | CA |
36 | 猫 | 我们 |
20 | 猪 | 我们 |
14 | Pig | Rs |
这可以通过某种分区来实现吗?我不确定如何在分组中示例选择语句...谢谢!
I have a table A that is like:
ID | PET | COUNTRY |
---|---|---|
45 | DOG | US |
72 | DOG | CA |
15 | CAT | CA |
36 | CAT | US |
21 | SNAKE | FR |
12 | SNAKE | IN |
20 | PIG | US |
14 | PIG | RS |
33 | HORSE | IQ |
90 | HORSE | ID |
The rows are paired/grouped based on matching PET. I would like to only select the pairs that include the US in the country. Basically each pair for the country value would have the US and another country/one of the values has to be the US. So for example, the resulting table would be
ID | PET | COUNTRY |
---|---|---|
45 | DOG | US |
72 | DOG | CA |
15 | CAT | CA |
36 | CAT | US |
20 | PIG | US |
14 | PIG | RS |
Would this be achieved by a partition of some sort? I am not sure how to case the select statement within a grouping... Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以根据PET加入,首先过滤出
country = US
。给出以下结果 -
You can just join based on PET, first filtering out for
country = US
.Gives following result -
使用
符合条件
和条件聚合:count_if(country ='us')(pet分区)> 0
- 组中至少必须是我们的计数(*)(pet)> 1
- 每行PET样本数据:
输出:
Using
QUALIFY
and conditional aggregation:COUNT_IF(COUNTRY = 'US') OVER(PARTITION BY PET) > 0
- at least one row in the group has to be USCOUNT(*) OVER(PARTITION BY PET) > 1
- more than one row per petSample data:
Output: