ROW_NUMBER() OVER(PARTITION BY ORDER BY )RN 只选一行
Posted snowfun
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ROW_NUMBER() OVER(PARTITION BY ORDER BY )RN 只选一行相关的知识,希望对你有一定的参考价值。
select PEGGED_SO_ID,PEGGED_SO_LINE_ID ,ITEM_ID ,QUANTITY ,LOCATION ,SITEID from IN_SEMI_ONHAND_LOCKED
where item_id in (‘000000101011003137‘,‘000000102011000038‘) ;
SELECT DISTINCT PEGGED_SO_ID,PEGGED_SO_LINE_ID ,ITEM_ID ,QUANTITY ,LOCATION ,SITEID ,ROW_NUMBER() OVER(PARTITION BY ITEM_ID,LOCATION ORDER BY NULL)RN FROM IN_SEMI_ONHAND_LOCKED where item_id in (‘000000101011003137‘,‘000000102011000038‘) ;
SELECT * FROM (SELECT DISTINCT PEGGED_SO_ID,PEGGED_SO_LINE_ID ,ITEM_ID ,QUANTITY ,LOCATION ,SITEID ,ROW_NUMBER() OVER(PARTITION BY ITEM_ID,LOCATION ORDER BY NULL)RN FROM IN_SEMI_ONHAND_LOCKED) where rn=1 and item_id in (‘000000101011003137‘,‘000000102011000038‘)
以上是关于ROW_NUMBER() OVER(PARTITION BY ORDER BY )RN 只选一行的主要内容,如果未能解决你的问题,请参考以下文章
Spark2 DataFrame数据框常用操作之分析函数--排名函数row_number,rank,dense_rank,percent_rank