日期:2014-05-16  浏览次数:20522 次

Oracle合并某个字段相同的两条记录
下面是Oracle的关于这个的Sql语句,先记录下来,后面在做详细解释分析/。
with temp_table as ( 

 selectaccount_id,USER_NICKNAME,THIRDPARTY_PLATFORM,thirdparty_id,THIRDPARTY_NAME,

 rank() over (partition by account_id order by 
account_id,USER_NICKNAME,THIRDPARTY_PLATFORM,thirdparty_id, THIRDPARTY_NAME) as num from ( select a.USER_NICKNAME, b.ACCOUNT_ID,

 b.THIRDPARTY_NAME,b.THIRDPARTY_PLATFORM, b.THIRDPARTY_ID from T_ACCOUNT a left 

join T_ACCOUNT_BIND b on b.account_id = a.SEQUENCE_ID where b.THIRDPARTY_ID in 

("+tidList+")) select a.account_id,a.user_nickname, a.THIRDPARTY_PLATFORM  

THIRDPARTY_PLATFORM1, a.thirdparty_id thirdparty_id1, a.THIRDPARTY_NAME 

THIRDPARTY_NAME1, b.THIRDPARTY_PLATFORM THIRDPARTY_PLATFORM2, b.thirdparty_id thirdparty_id2,  b.THIRDPARTY_NAME THIRDPARTY_NAME2 from (select * from temp_table 

where num = 1) a left join (select * from temp_table  where num = 2) b on a.account_id= b.account_id "