我有一个包含customer_id和order_id的表,我想根据customer_id进行排序。如何在Vertica SQL中完成?
c_id o_id 1 1 2 3 1 4 2 5 3 6 3 7
我想:
c_id o_id seq 1 1 1 1 4 2 2 3 1 2 5 2 3 6 1 3 7 2
答案 0 :(得分:2)
据我所知,Vertica支持(标准)窗口函数,因此以下内容应该有效:
select c_id,
o_id,
row_number() over (partition by c_id order by o_id) as seq
from the_table
order by c_id, o_id