같은 표 의 다 중 필드 를 조회 하 는 동시에 기 록 된 SQL 문 구 를 반복 합 니 다.

4363 단어 Oaclesql

 


                SQL   
  :7th string 


           (  :peosons) 
     、    、                   select   p1.*   from   persons   p1,persons   p2   where   p1.id<>p2.id   and   p1.cardid   =   p2.cardid   and   p1.pname   =   p2.pname   and   p1.address   =   p2.address 
        . 
         SQL   
   
1. rowid   
2. group by   
3. distinct   
   
1。 rowid   
  Oracle  rowid  ,    ,      ,    : 
   : 
     select * from table1 a where rowid !=(select   max(rowid)   
     from table1 b where a.name1=b.name1 and a.name2=b.name2......) 
   : 
    delete   from table1 a where rowid !=(select   max(rowid)   
     from table1 b where a.name1=b.name1 and a.name2=b.name2......) 
2.group by   
   : 
  select count(num), max(name) from student --        ,     name   
  group by num 
  having count(num) >1 -- num       num   ,          
   : 
  delete from student 
  group by num 
  having count(num) >1 
                 。 
3. distinct   -          
create table table_new as   select distinct *   from table1 minux 
truncate table table1; 
insert into table1 select * from table_new; 


               

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 peopleId  in (select  peopleId  from people  group  by  peopleId   having  count(peopleId) > 1) 
and rowid not in (select min(rowid) from  people  group by peopleId  having count(peopleId )>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) 


( ) 
    
 A        “name”, 
         “name”       , 
                   ,“name”       ; 
Select Name,Count(*) From A Group By Name Having Count(*) > 1 
             : 
Select Name,sex,Count(*) From A Group By Name,sex Having Count(*) > 1 


( ) 
    
declare @max integer,@id integer 
declare cur_rows cursor local for select    ,count(*) from    group by     having count(*) >; 1 
open cur_rows 
fetch cur_rows into @id,@max 
while @@fetch_status=0 
begin 
select @max = @max -1 
set rowcount @max 
delete from    where     = @id 
fetch cur_rows into @id,@max 
end 
close cur_rows 
set rowcount 0 


    
"    "           ,         ,            ,             ,  Name    ,                  。 


  1、       ,      ,   
select distinct * from tableName 
                。 
               (      1 ),          
select distinct * into #Tmp from tableName 
drop table tableName 
select * into tableName from #Tmp 
drop table #Tmp 
                    ,           。 


  2、                       ,       
           Name,Address,                
select identity(int,1,1) as autoID, * into #Tmp from tableName 
select min(autoID) as autoID into #Tmp2 from #Tmp group by Name,autoID 
select * from #Tmp where autoID in(select autoID from #tmp2) 
      select    Name,Address       (     autoID  ,        select       ) 


( ) 
     
select * from tablename where id in ( 
select id from tablename 
group by id 
having count(id) > 1 
) 

좋은 웹페이지 즐겨찾기