sql server 常用查询

1.查询表内重复的字段

select id from table1 where id in(select id from table1 group by id having count(id)>1)

2.select查询添加自增长的列 作为标识列

例子:Select (Select sum(1) from Table1  where ID <= a.ID) as xuhao,* from Table1 a

 

 

SQL 重复数据的提取与过滤

 

提取重复数据

SELECT * FROM tablename GROUP BY colname HAVING COUNT(*) > 1 

 

过滤重复数据

SELECT * FROM tablename GROUP BY colname HAVING COUNT(*) = 1

http://blog.csdn.net/zhoujiaoshou/article/details/7928351

 

============================================

根据日期模糊查询

Convert(varchar,日期字段,120) LIKE '%2008-03-22%'

========================================

查询一个表内的几个字段 导入另外一个表内

insert into T_PetitionLetter(LetterTown,LetterVillage,Informer,InformerContact,[Description])
select 乡镇,村名,户主姓名,联系电话,群众需求诉求 from 畜禽污染群众诉求$

 

sql查询时增加自动编号

参考:http://blog.163.com/yijia_luo/blog/static/1253883201262273718944/

Select (Select sum(1) from TableName where id<= a.id) as iid,* from TableName a

 

 

 

 

 

 

 

posted @ 2012-08-31 15:50  高山-景行  阅读(232)  评论(0编辑  收藏  举报