殊途哲

01月 17, 2008

SQL重复记录处理

归类于: SQLServer — shutuzhe @ 11:12 pm

1 查询不重复记录条数:

select count(distinct culumn) from tablename

2 导出不重复记录到新表:

select distinct * into newtable from oldtable

3
3 查询重复记录

SELECT school, class, name, num FROM table GROUP BY school, class, name, num HAVING (COUNT(num) > 1)

select * from 表 group by 字段 having count(字段)>1

4查询重复记录条数

SELECT count(*) as cout,school, class, name, num FROM table GROUP BY school, class, name, num HAVING (COUNT(num) > 1)

5查询一个表中有在另一个表中没有的记录:

select * from table1 where column not in (select column from table2)

Powered by WordPress