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‘) 

原文地址:https://www.cnblogs.com/Snowfun/p/9162880.html

时间: 2024-10-12 19:48:45

ROW_NUMBER() OVER(PARTITION BY ORDER BY )RN 只选一行的相关文章

Oracle中的 row_number() over (partition by order by ) 用法

oracle 里面经常这样用 select col1,col2..., row_number() over (partition by colx order by coly) from table_name;; 这句话的意思是把表中的数值按照colx 分组,每一组内部按照coly排序,同时 row_number()返回排序之后该记录在改组内部的序号. 比如我们知道有emp表如下: SQL> SELECT * FROM SCOTT.EMP; EMPNO ENAME JOB MGR HIREDATE

row_number() over (partition by....order by...)用法 分组排序

转载来源:http://www.cnblogs.com/Kazaf/archive/2011/06/30/2094015.html row_number() OVER (PARTITION BY COL1 ORDER BY COL2) 表示根据COL1分组,在分组内部根据 COL2排序,而此函数计算的值就表示每组内部排序后的顺序编号(组内连续的唯一的) SELECT G.*, ROW_NUMBER() OVER(PARTITION BY a ,b ORDER BY c DESC) ROWN fr

去重 ROW_NUMBER() OVER(PARTITION BY 分组字段 ORDER BY 排序字段) RN

关键字  ROW_NUMBER() OVER(PARTITION BY 分组字段 ORDER BY 排序字段) RN 按照分组字段进行排序并标编号 ROW_NUMBER() OVER(PARTITION BY 分组字段 ORDER BY 排序字段) RN 语法 ROW_NUMBER() OVER(PARTITION BY XMJL_UID ORDER BY XMCREATETIME) RN 实例 SELECT XMJL_UID,XMJL,XMCREATETIME,ROW_NUMBER() OVE

row_number() over(partition by a order by b desc) rn 用法

ow_number() OVER (PARTITION BY COL1 ORDER BY COL2) 表示根据COL1分组,在分组内部根据 COL2排序,而此函数计算的值就表示每组内部排序后的顺序编号(组内连续的唯一的) 实际应用 取最新的数据 select * from (select hlpr.emplid, hlpr.deptid, hlpr.create_time, row_number() over (partition by hlpr.emplid order by hlpr.cre

分组 根据某一列进行排序,根据shopid分组,用createTime排序,返回row_number()序号 select no =row_number() over (partition by shopId order by createTime desc), * from Goods_info

over不能单独使用,要和分析函数:rank(),dense_rank(),row_number()等一起使用.其参数:over(partition by columnname1 order by columnname2)含义:按columname1指定的字段进行分组排序,或者说按字段columnname1的值进行分组排序.例如:employees表中,有两个部门的记录:department_id =10和20select department_id,rank() over(partition

【SQL】ROW_NUMBER() OVER(partition by 分组列 order by 排序列)用法详解+经典实例

原文:[SQL]ROW_NUMBER() OVER(partition by 分组列 order by 排序列)用法详解+经典实例 #用法说明 select row_number() over(partition by A order by B ) as rowIndex from table A :为分组字段 B:为分组后的排序字段. table 表的结构 多为:  多人 多条的相关数据.(比如:订单信息) 此条sql语句,多用于对数据进行分组排序,并对每个组中的数据分别进行编号,编号从1开始

Row_number() OVER(PARTITION BY xxx ORDER BY XXX)分组排序

--//创建一个信息表 CREATE TABLE user_student(id decimal(18,0) identity(1,1),st_name nvarchar(30),class nvarchar(10),score decimal(18,2)) --//插入测试数据============start=================== insert into user_student(st_name,class,score) values('张三','甲','90') inser

row_number() OVER (PARTITION BY COL1 ORDER BY COL2)

--表示根据COL1分组,在分组内部根据 COL2排序,而此函数返回的值就表示每组内部排序后的顺序编号(组内连续的唯一的) create table student (id int ,classes int ,score int); insert into student values(1,1,89); insert into student values(2,1,90); insert into student values(3,1,76); insert into student value

ROW_NUMBER() OVER(PARTITION BY COLUMN ORDER BY COLUMN DESC)函数的使用

ROW_NUMBER() OVER(PARTITION BY COLUMN ORDER BY COLUMN DESC)函数的作用是指定COLUMN(列)进行分区,在分区内指定COLUMN(列)进行排序,其中PARTITION BY COLUMN 为分区函数.代码具体实现如下 不进行分区的排序方式--对商品价格的升序排序 SELECT A.*, ROW_NUMBER() OVERORDER BY PRICE ASC) AS ROW_FLG FROM COMMODITY A 进分区的排序方式--对商