1:随机取出数据表中数据
select top n * from table order by newid()
2:取出插入表中的最新ID
insert into table vlues() select @@identity
3:取出表中10-20的数据
select top 10 * from table where id not in(select top 20 id from table)
4:判断字段并赋于不同值
select columnName1=
case columnName1
when 1 then 'value'
end
from table
5:获取最后更新时间的所有列
select max(addDate) ,userName from table group by userName order by addDate desc
6:删除表中所有重复记录
delete from table where columnName =(select columnName from table group by columnName
having count(*)>1)
7:获取日期和时间
select convert(char(20),getDate(),20) value from table
select convert(char(8),getDate(),108) value from table