oracle重复字段取第一行值

select * from(
select k.kind as kinds,d.*,x.sum, row_number() OVER(PARTITION BY d.TKNUMBER ORDER  BY d.NOWDATE desc) as row_flg from(  --里面就是个查询,不管,主要是外面的
select t.*,s.TECHNICAN_ID from ZHYY_TK t
 left join
ZHYY_TK_BASE s
on t.TKNUMBER = s.TKNUMBER
) d
left join (
 select sum(AMOUNT) as sum,TKNUMBER from ZHYY_TK group by TKNUMBER
) x on d.TKNUMBER = x.TKNUMBER
  left join
(
  select TKNUMBER,wmsys.wm_concat(KIND) as kind
  from ZHYY_TK
  group by TKNUMBER
) k on k.TKNUMBER = x.TKNUMBER
  and d.TECHNICAN_ID = 'A24672AABCC241368245BAA244510895'
order by d.TKNUMBER  asc
)  h where h.row_flg = '1'

row_number() OVER (PARTITION BY COL1 ORDER BY COL2) 表示根据COL1分组,在分组内部根据 COL2排序,而此函数计算的值就表示每组内部排序后的顺序编号(组内连续的唯一的).

你可能感兴趣的:(oracle)