软件测试面试中会碰到sql语句的笔试题

在面试大公司的时候,很多情况下都有笔试题,笔试题经常包含软件测试的基础知识点、逻辑题、等等,有时候也会碰到关于sql语句的题目,今天来列举一些简单的sql语句,希望对大家有所帮助。

创建表语句

SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[stuscore]( [name] [varchar](50) COLLATE Chinese_PRC_CI_AS NULL, [subject] [varchar](50) COLLATE Chinese_PRC_CI_AS NULL, [score] [int] NULL, [stuid] [int] NULL) ON [PRIMARY] GOSET ANSI_PADDING OFF

插入数据

insert into dbo.stuscore values (‘张三’,’数学’,89,1);insert into dbo.stuscore values (‘张三’,’语文’,80,1);insert into dbo.stuscore values (‘张三’,’英语’,70,1);insert into dbo.stuscore values (‘李四’,’数学’,90,2);insert into dbo.stuscore values (‘李四’,’语文’,70,2);insert into dbo.stuscore values (‘李四’,’英语’,80,2);

查询语句

select * from dbo.stuscore

问题:

1.计算每个人的总成绩并排名(要求显示字段:姓名,总成绩)

select name,SUM(score) as allscore from dbo.stuscore

group by name

order by allscore;

2.计算每个人的总成绩并排名(要求显示字段: 学 ,姓名,总成绩)

select stuid,name,SUM(score) as allscore from dbo.stuscore

group by name,stuid

order by allscore;

3.计算每个人单科的最高成绩(要求显示字段: 学 ,姓名,课程,最高成绩)

select t1.stuid,t1.name,t1.subject,t1.score from stuscore t1,

(select stuid,max(score) as maxscore from stuscore group by stuid) t2

where t1.stuid=t2.stuid and t1.score=t2.maxscore;

4.计算每个人的平均成绩(要求显示字段: 学 ,姓名,平均成绩)

select stuid,name,AVG(score) avgscore from dbo.stuscore

group by stuid,name;

5.列出各门课程成绩最好的学生(要求显示字段: 学 ,姓名,科目,成绩)

select t1.stuid,t1.name,t1.subject,t1.score from stuscore t1,(

select subject,MAX(score) as maxscore from stuscore group by subject)t2

where t1.subject = t2.subject and t1.score = t2.maxscore;

6.列出各门课程成绩最好的两位学生(要求显示字段: 学 ,姓名,科目,成绩)

select t1.* from stuscore t1 where t1.stuid in (

select top 2 stuid from stuscore where subject = t1.subject order by score desc)

order by t1.subject;

7.列出数学成绩的排名(要求显示字段:学 ,姓名,成绩,排名)

select stuid,name,score,

(select count(*) from stuscore t1 where subject =’数学’ and t1.score > t2.score)+1 as 名次 from stuscore t2

where subject=’数学’ order by score desc;

觉得文章不错就点个在看呗,转发就更好了

软件测试之直播类产品的直播质量方法小结

解决自动化测试时遇到验证码的两种方法

软件测试之浦发银行面试题

APP UI自动化测试常见面试题小结

项目上线前验收测试流程

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年6月25日
下一篇 2021年6月25日

相关推荐