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

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)
(二)
比方说
在A表中存在一个字段“name”,
而且不同记录之间的“name”值有可能会相同,
现在就是需要查询出在该表中的各记录之间,“name”值存在重复的项;
Select Name,Count(*) from A Group By Name Having Count(*) > 1
如果还查性别也相同大则如下:
Select Name,sex,Count(*) from A Group By Name,sex Having Count(*) > 1
(三)
方法一
declare @max integer,@id integer
declare cur_rows cursor local for select 主字段,count(*) from 表名 group by 主字段 having count(*) >; 1
open cur_rows
fetch cur_rows into @id,@max
while @@fetch_s


相关文档:

动态sql语句基本语法


SQL code
动态sql语句基本语法
1 :普通SQL语句可以用Exec执行
eg: Select * from tableName
Exec('select * from tableName')
Exec sp_executesql N'select * from tableName' -- 请注意字符串前一定要加N
2:字段名,表名,数据库名之类作为变量时,必须用动态SQL
eg:
declare @ ......

SQL 2008 怎样还原数据库?

因现在的工作需要,
我得从WinForm的平台,
转型到WebForm的页面。
有一年多没有接触SQL Server了,
虽然大学时有点基础,
但也忘记得差不多了。
因为Asp.net型的B/S网站和WinForm的还是有点不同,
现在工作起来不是那么得心应手。
温故而知新,
就把以前实习时做的的网站源代码拿出来看看。
因为要用到SQL 2005S ......

SQL SERVER字段类型说明

 
bit:0或1的整型数字
int:从-2^31(-2,147,483,648)到2^31(2,147,483,647)的整型数字
smallint:从-2^15(-32,768)到2^15(32,767)的整型数字
tinyint:从0到255的整型数字

decimal:从-10^38到10^38-1的定精度与有效位数的数字
numeric:decimal的同义词

money:从-2^63(-922,337,203,685,477.580 ......

关于SQL语句的自动生成

在我们的日常编程中,数据库的程序基本上都要与SQL语句打交道,SQL语句的编写不可避免的成为一个头疼的工作。且因为SQL语句是STRING类型,因此在编译阶段查不出错,只有到运行时才能发现错误。
本文的解决方案,通过自动生成SQL语句,在一定程度上降低出错的概率,从而提高编程效率。     public int ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号