易截截图软件、单文件、免安装、纯绿色、仅160KB

SQL重复记录查询

 SQL重复记录查询
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)


相关文档:

用自定义的SQL脚本创建SQL Server数据库安装例子

Creating a Sample Installation that Creates a SQL Server Database by Running Customized SQL Script
InstallShield 2009
 用自定义的SQL脚本创建SQL Server数据库安装例子
Project 项目
This information applies to the following project types: 此信息是用于下面的项目类型
• Basic MSI
&b ......

SQL用DataDiff查询的怪现象而引发的思考。。

今天又看到新加坡的同事发过来的一段SQL语句,还是老问题,时间对比直接用大于小于号。叹了声气后,手动给改成datediff了,可是一运行出错,错误提示如下:
Msg 241, Level 16, State 1, Line 1
Conversion failed when converting datetime from character string.
为了说明方便,这里就简化一个例子好了。
create tab ......

在sql server 2000中调用系统时间

select getdate()
是显示当前系统时间,输出的日期格式与本机日期格式有关,假入你想在什么情况下都显示成2006-12-15 10:37:00这种形式则需要转换一下
select convert(varchar(30),getdate(),20)
显示是星期几的语句是
select datename(weekday,getdate())
日期加星期的话直接加在一块就可以了
select convert(varcha ......

SQL用DataDiff查询的怪现象而引发的思考(2)

在脑子里老是记得当初写SQL的时候,总是有人提醒对于主键的条件要写在前面,至于为什么现在总是记不清楚了。但是SQL中where 条件的执行顺序跟主键以及索引有很大的关系。
把上片中的表a 加上主键:
alter table
add constraint pk_a_id primary key (id)
然后在运行上篇中出错的例句:
select * from a where id in (1 ......

sql语句的使用

以下是我在学习中的点滴记录,如果有错误的地方或者缺少部分,请各位大侠不吝指教。小弟在此谢过了
1.select count(*) 和select count(id) 之间的区别。
select count(*) 统计所有记录个数,包括空记录。
Select count(Id) 统计所有记录个数,不包括null记录。
2.delete & truncate 的区别
trunc ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号