您的位置:程序门 -> oracle -> 基础和管理



怎么通过sql语句删除重复的记录,只保留一条,并记录重复的次数?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


怎么通过sql语句删除重复的记录,只保留一条,并记录重复的次数?
发表于:2007-04-19 22:35:57 楼主
id                           newcode                     frequent                    
    ---------------------------------------------      
    1                           ht-8008sr                   1
    2                           ht-8008sr                   1  
    3                           ht-8008sf                   1
    4                           ht-8008sf                   1    
?1.删除整个表中重复的id号记录,只保留一条记录。并记录重复的次数?该如何实现!谢谢!
得到
    id                           newcode                     frequent                    
    ---------------------------------------------      
    1                           ht-8008sr                   1
    2                           ht-8008sf                   2  
发表于:2007-04-20 09:35:331楼 得分:0
select   max(newcode),count(frequent)   from   table   group   by   newcode;
发表于:2007-04-20 10:48:422楼 得分:0
delete   from   table   t   where   exits(select   newcode   from   table   t1   where   t1.id!=t.id)
发表于:2007-04-20 17:32:443楼 得分:0
已在
http://community.csdn.net/expert/topic/5478/5478790.xml?temp=.3844568
中回复


快速检索

最新资讯
热门点击