首页 > 数据库技术 > 详细

SQL语言

时间:2016-12-29 23:09:56      阅读:277      评论:0      收藏:0      [点我收藏+]

表:user  列:id,name,age,createTime

1、找出表中最小年龄的用户:

  select min(age) from user ;

     select top 1 age from user order by age;

  select * from user where age<=all(select age from user);

2、找出名字重复的用户:

  select * from user where name in (select name from user group by name having(count(name)>1));

3、复制表结构、拷贝表数据,联查:

  select * into user1 from user where 1=0;

  select * into user1 from user;

  select * from user,user1,user2 where 关联条件;

4、SQL Server中创建临时表:

  create table #temp(字段1 类型,字段2 类型...);临时表在表名前加#

5、最新写入的用户信息:

  select * from user where createTime = (select max(createTime) from user);

6、取第5行到第7行的用户信息:

  select * from user order by id limit 4,3;索引从4开始,取三个数据

  slelect top 3 from user where id not in (select top 4 id from user order by id) order by id ;

SQL语言

原文:http://www.cnblogs.com/nowayZz/p/6234821.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!