我有下面的数据集,我想根据特定列上的组(或其他一些函数)获得特定的列值。我的数据集看起来如下:
id zip Action content duration OS TIME
================================================
1 11 START DELL LINUX 12
1 11 JUMP HP UNIX 14
1 11 STOP HP 10 LINUX 16
1 11 START WIN LINUX 2
1 11 JUMP HP UNIX 4
1 11 STOP SONY 12 LINUX 15
2 12 START HP UNIX 3
2 12 STOP FOP 2 WINDOWS 10
--------------------------------------------我希望根据相同的(id,zip)组获得所有列的值,其中Action='STOP‘和最大时间在过滤记录之外。我的预期产出是:
id zip Action content duration OS
========================================
1 11 STOP HP 10 LINUX
2 12 STOP FOP 2 WINDOWS
--------------------------------------------如何使用蜂巢实现同样的目标?请帮帮忙。
发布于 2017-06-10 17:05:06
row_number
select id,zip,Action,content,duration,OS
from (select *
,row_number() over
(
partition by id,zip
order by time desc
) as rn
from mytable
where action = 'STOP'
) t
where rn = 1+----+-----+--------+---------+----------+---------+
| id | zip | action | content | duration | os |
+----+-----+--------+---------+----------+---------+
| 1 | 11 | STOP | HP | 10 | LINUX |
| 2 | 12 | STOP | FOP | 2 | WINDOWS |
+----+-----+--------+---------+----------+---------+https://stackoverflow.com/questions/44474264
复制相似问题