» 您尚未登录:请 登录 | 注册 | 标签 | 帮助 | 小黑屋 |


发新话题
打印

[其他] 求问编程DX们一句SQL语句

要求是用SQL语句删除一张表中所有重复的行(无ID)

如:
字段:username
     11   
     22
     33
     11
     22
     33
     44
     55

希望语句执行后的结果是
字段:username
     44
     55      

能用一句话实现就最好了,不能的话问题也不大:D

[ 本帖最后由 use2 于 2007-12-25 15:58 编辑 ]


TOP

先count 出来distinct username的个数,然后删除个数 >1的就行了



TOP

还是不太明白
LS能说具体点吗?谢谢~


TOP

delete from username  where id in(select count(*)>1 from username group by id)

TOP

多谢~!!:D

TOP

不知道

[ 本帖最后由 cc0128 于 2007-12-25 18:08 编辑 ]

TOP

引用:
原帖由 iorilu 于 2007-12-25 16:28 发表
delete from username  where id in(select count(*)>1 from username group by id)
SQLSERVER里这样写不行的吧

TOP

delete from table as a where (select count(*) from table as b where b.username=a.username)>1

TOP

LS这个好象也不行哦.........

TOP

delete from table where username in (select username from (select username,count(*) from table group by username having count(*)>1))

TOP

delete from Table
where username in
(select distinct username from Table group by username having count(username)>1)

TOP

呵呵,LS的可以了
谢谢大家~!!!

TOP

DELETE FROM [table]
WHERE EXISTS
                  (SELECT COUNT(username), username
                   FROM    [table] t
                   WHERE t.username = username
                   GROUP BY username
                   HAVING (COUNT(username) > 1))

TOP

发新话题
     
官方公众号及微博