1. 找出表ppp里面最小的数,可以使用min函数
select *from ppp where num=(select Min(num) from ppp)
2.选择表ppp2中num重复的记录
select * from ppp2 where num in(select num from ppp2 group by num having (count(num) > 1))
3.复制表(只复制结构,源表明:A,新表名:B)
select * into B from A
拷贝表
select *into B from A
四表查询
select * from A,B,C,D where 关联条件
4.有数据表A,有一个字段LASTUPDATETIME,是最后更新的时间,如果要查询最新更新过的记录,如何写SQL语句?
SQL codeselect * from [数据表A]
where LASTUPDATETIME=(select max(LASTUPDATETIME) from [数据表A])
5.有一个数据库,只有一个表,包含1000个记录,怎么来把第5行和第7行的记录取出来?
select top 3 userid from T where userid not in(select top 4 userid from T order by userid) order by userid
6.使查询a时能够统计a的数量
select name,count(*) as [count] from 表a where name= 'a' group by name
7.写一个SQL语句,找出修2~3门的学生的名字
select * from Student as tmp
where (select count(*) from Study where StudentID = tmp.StudentID) between 2 and 3
8.创建一个表
CREATE TABLE users(
users varchar(50) NOT NULL,
pwd varchar(50) NOT NULL,
type int NOT NULL
)
GO
9.
select *from ppp where num=(select Min(num) from ppp)
2.选择表ppp2中num重复的记录
select * from ppp2 where num in(select num from ppp2 group by num having (count(num) > 1))
3.复制表(只复制结构,源表明:A,新表名:B)
select * into B from A
拷贝表
select *into B from A
四表查询
select * from A,B,C,D where 关联条件
4.有数据表A,有一个字段LASTUPDATETIME,是最后更新的时间,如果要查询最新更新过的记录,如何写SQL语句?
SQL codeselect * from [数据表A]
where LASTUPDATETIME=(select max(LASTUPDATETIME) from [数据表A])
5.有一个数据库,只有一个表,包含1000个记录,怎么来把第5行和第7行的记录取出来?
select top 3 userid from T where userid not in(select top 4 userid from T order by userid) order by userid
6.使查询a时能够统计a的数量
select name,count(*) as [count] from 表a where name= 'a' group by name
7.写一个SQL语句,找出修2~3门的学生的名字
select * from Student as tmp
where (select count(*) from Study where StudentID = tmp.StudentID) between 2 and 3
8.创建一个表
CREATE TABLE users(
users varchar(50) NOT NULL,
pwd varchar(50) NOT NULL,
type int NOT NULL
)
GO
9.