- 表结构:id name subject score createdate
- 建表语句:
-
Code
- 向表预赛几条数据:
Code
- 1. 创建时间为3天前0点创建的纪录,20分钟前创建的纪录?
-
select * from Score
where DATEDIFF(d,createdate,GETDATE())>3
select * from Score
where DATEDIFF(n,createdate,GETDATE())>20 - 2. 3门以上不及格学生的学生姓名?
-
select [name] from Score
where score<60
group by [name]
having COUNT(*)>=3 - 3. id name
1 a
2 b
3 a
4 a
id为identity,只留一条a与一条b -
--select * into Score_Test3 from Score
select * from Score
select * from Score_Test3
delete from Score_Test3
where id not in
(
select max(id) from Score_Test3 group by [name]
) - 4. 总分排名5-7的学生姓名(name,score),最好写成存储过程,请注意并列排名的问题
-
--select * into Score_Test4 from Score
select * from Score
select * from Score_Test4
select top 3 t2.*
from
(select top 7 [name],sum(score) as totalScore from Score_Test4 group by [name] order by sum(score)) t2
order by t2.totalScore - 没有考虑并列排名问题,还待斟酌。。。
作者:MaoBisheng
出处:http://maobisheng.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
出处:http://maobisheng.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。