µ±Ç°Î»Ö㺠´úÂëÃÔ >> SQL >> SQL找出é‡�å?æ•°æ�®å�?¿�留一æ�
  Ïêϸ½â¾ö·½°¸

SQL找出é‡�å?æ•°æ�®å�?¿�留一æ�

Èȶȣº149   ·¢²¼Ê±¼ä£º2016-05-05 11:38:25.0
SQL找出é‡�å?æ•°æ�®å�?¿�留一æ�?
用SQLè¯?�¥,删除掉é‡�å¤�项å�?¿�留一æ�?/div>

在几å�ƒæ�¡è®°å½•é‡?存在ç�?些相å�Œçš„记录,如何能用SQLè¯?�¥,删除掉é‡�å¤�çš„å‘?br>1ã€�查找表ä¸??余的é‡�å?记录,é‡�å¤�è?录是根æ�®å�•个字æ?(peopleId)æ�¥åˆ¤æ–­
select * from people
where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)

2ã€�删除表ä¸??余的é‡�å?记录,é‡�å¤�è?录是根æ�®å�•个字æ?(peopleId)æ�¥åˆ¤æ–­ï¼Œå�ªç•™æœ‰rowidæœ?å°�的记录
delete from people
where   peopleName in (select peopleName    from people group by peopleName      having count(peopleName) > 1)
and   peopleId not in (select min(peopleId) from people group by peopleName     having count(peopleName)>1)

3ã€�查找表ä¸??余的é‡�å?记录(å?ä¸?­—段)
select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)

4ã€�删除表ä¸??余的é‡�å?记录(å?ä¸?­—段),å�ªç•™æœ‰rowidæœ?å°�的记录
delete from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)

5ã€�查找表ä¸??余的é‡�å?记录(å?ä¸?­—段),ä¸�包å�«rowidæœ?å°�的记录
select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)   

6.消除ä¸?ä¸?­—段的左边的ç?ä¸?ä½�:

update tableName set [Title]=Right([Title],(len([Title])-1)) where Title like '�'

7.消除ä¸?ä¸?­—段的å�³è¾¹çš„ç?ä¸?ä½�:

update tableName set [Title]=left([Title],(len([Title])-1)) where Title like '%�

8.å�‡åˆ é™¤è¡¨ä¸??余的é‡�å?记录(å?ä¸?­—段),ä¸�包å�«rowidæœ?å°�的记录
update vitae set ispass=-1
where peopleId in (select peopleId from vitae group by peopleId

 

select *from r_people_report_bak ppp where 1=1and length(ppp.reporting_period)<=6and ppp.organization_code  || '_' ||to_char(to_date(ppp.reporting_period ,'YYYY-mm'),'yyyy') || '-' || to_char(to_date(ppp.reporting_period ,'YYYY-mm'),'mm')|| '_' || ppp.datilor_allin (select pp.organization_code || '_' || pp.aa || '_' || pp.datilor_all from (select p.people_id,p.organization_code,p.datilor_all,to_char(to_date(p.reporting_period ,'YYYY-mm'),'yyyy') || '-' || to_char(to_date(p.reporting_period ,'YYYY-mm'),'mm') aafrom r_people_report_bak p where  p.reporting_period is not null ) ppgroup by pp.aa ,pp.organization_code,pp.datilor_allhaving count(1) > 1 )

 

 

 

  Ïà¹Ø½â¾ö·½°¸