Postgres 窗口函数

参考: https://www.cnblogs.com/qianxunman/p/12105961.html

        如果需要在类别(type)内按照价格(price) 升序排列(就是在类别内做排序),该怎么做呢?即在一个type范围内子排序

  当然也很简单,只需要在窗口(over())中声明分隔方式 Partition .

  分类排序序号,row_number() 实现>

    select type,name,price,row_number() over(PARTITION by type order by price asc) as idx from products ;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章