如何检查表中两列中的值在SQL中是否为一对一?我正在考虑按两列分组并获得第一个值,在Python中,它将如下所示:
df.groupby(['col1', 'col2']).first()示例数据:
col1 col2 timestamp data
1 1 2 2017-01-02 13:14:53.040 10.0
2 1 2 2017-01-02 13:14:54.040 10.0
3 1 4 2017-01-02 13:14:55.040 10.0
4 10 33 2017-01-02 13:14:56.040 10.0
...预期输出:
col1 col2 timestamp data
1 1 2 2017-01-02 13:14:53.040 10.0
3 4 2017-01-02 13:14:55.040 10.0
4 10 33 2017-01-02 13:14:56.040 10.0
...在SQL中有没有等价物?如果不是,那么在SQL中检查这两列是否一对一的最佳方法是什么?
发布于 2021-04-06 09:41:49
您似乎想要给定值对的第一行,其中" first“基于时间戳:
select t.*
from (select t.*,
row_number() over (partition by col1, col2 order by timestamp) as seqnum
from t
) t
where seqnum = 1;https://stackoverflow.com/questions/66961715
复制相似问题