SQL语句

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值