90s手机电影,北京奥运会开幕式高清nbc,地铁笨蛋4小游戏
1、查找重复记录
①如果只是不想在查询结果中存在重复记录, 可以加distinct
select distinct * from testtable
②如果是想查询重复的记录及其数量 select userid,username,count(*) as '记录数'
from testtable
group by userid,username
having count(*)>1
③id不重复, 但是字段重复的记录只显示一条 select * from testtable where userid in
(select max(userid) as userid from testtable group by username,sex,place)
2、删除重复记录
①一种思路是利用临时表, 把查询到的无重复记录填充到临时表, 再把临时表的记录填充回原始表
select distinct * into #temp from testtable
drop table testtable
select * into testtable from #temp
drop table #temp
②删除id不重复, 但是字段重复的记录(就是按字段查询出相同字段记录中最大的id,然后保留此记录, 删除其他记录).(group by 的字段, 有点麻烦).
delete testtable where userid not in
(select max(userid) as userid from testtable group by username,sex,place)
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
相关文章:
-
-
-
sql某个日期是当年的第几周
/* *周一作为一周的开始 *当年的1月1号所在的周算作第一周 */ CREATE function GetWeekIndexFirstDate ( @...
[阅读全文]
-
-
数据库SQL---范式
1、数据冗余导致的问题:冗余存储、更新异常、插入异常、删除异常。 2、函数依赖:一种完整性约束。 在关系模式r(R)中,α属于R,β属于R。 1)α函数...
[阅读全文]
-
-
数据库SQL---查询
1、查询所有列 select *from emp;--*表示所有的,from emp表示从emp表中查询。 2、查询指定列 select empno,e...
[阅读全文]
-
-
-
-
网友评论