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 ;

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