首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

oracle 取A表的数据,联系关系B表的id最小值

2012-10-07 
oracle 取A表的数据,关联B表的id最小值1.先关联出数据作为临时表a,取出最小值,然后将剩余的行数去掉最小值

oracle 取A表的数据,关联B表的id最小值
1.先关联出数据作为临时表a,取出最小值,然后将剩余的行数去掉最小值的行,即可
with   a   as (SELECT A.cus_No FROM A  ,
B  where B.rel_org_no(+)=A.cus_no  and t.Stop_Flag='N' )
SELECT a.* from a
where usr_id in  (select min(usr_Id) from users group by rel_org_no )
union
SELECT a.* from a
where cus_No not in (
SELECT cus_No from a
where usr_id in  (select min(usr_Id) from users group by rel_org_no )  )

2.oracle update 序号,按照主表进行分类

update  t set t.ord_seq=
(select num from (select rowid , row_number()over (partition by b.ord_no order by rowid ) num  from  b) c
where t.rowid=c.rowid)

热点排行