SqlServer常见的一些面试题笔记(老鸟勿入)

面试常见的Sql语句和大家分享:

问题1:Sql查询重复问题
解答:
---查询重复数据
example:
表名:Cpf_file
字段名:cpf01
select * from Cpf_file where cpf01 in (select cpf01 from Cpf_file group by cpf01 having count(1) >= 2)

 

问题2:
Sql去除重复问题
解答:
example:
原表:TestEisUser
临时表:TempTB
--第一步 将不重复的数据记录筛选出来存储到新的临时表中
select distinct * into TempTB from TestEisUser
--第二步 删除原表中的数据
drop table TestEisUser
--将TempTB表中的数据复制到TestEisUser中
select distinct * into TestEisUser from TempTB

 

问题3:
数据分页问题: 

语句格式:

SELECT TOP 页大小 *
FROM TestTable
WHERE (ID NOT IN
(SELECT TOP 页大小*页数 id
FROM 表
ORDER BY id))
ORDER BY ID

example:
---筛选出表TestEisUser从第31-40条记录,主键UID,UID可以不连续
SELECT TOP 10 *
FROM TestEisUser
WHERE (UID NOT IN
(SELECT TOP 30 UID
FROM TestEisUser
ORDER BY UID))
ORDER BY UID

posted @ 2012-04-17 16:07  智客工坊  阅读(546)  评论(0编辑  收藏  举报