row_number over (partition by a order by b desc)
时间: 2023-12-19 22:32:28 浏览: 160
row_number,根据多个字段过滤,partition by
以下是使用row_number() over(partition by name order by timestamp desc)的示例:
```sql
SELECT *, ROW_NUMBER() OVER(PARTITION BY name ORDER BY timestamp DESC) AS idx
FROM your_table_name;
```
这个示例中,ROW_NUMBER()函数根据name分区,并按照timestamp降序排列,为每个分区中的行分配一个唯一的行号。
阅读全文