新题速看!2021阿里、腾讯、字节都在问的SQL数据库笔试题及答案都给你整理好啦!

  前  言

2021到了最后一个月份,年后肯定有蛮多小伙伴需要跳槽换工作,但对于年限稍短的软件测试工程师,难免会需要进行笔试,而在笔试中,基本都会碰到一道关于数据库的大题,今天这篇文章呢,就收录了下最近学员反馈上来的一些数据库笔试真题,包含答案!

1、依据以下学生表、班级表,按要求写 SQL

答案:

1、

select * from student a

left join class b on a.c_id = b.id

where score = (

select max(score) from student)

2、

select b.name,count(*),avg(score) as avgScore from student a,class b

where a.c_id = b.id

group by b.name

order by avgScore;

2、Table A 保存客户的基本信息;Table B 保存客户的资产负债信息。按要求写 SQL

答案:

(1)select ID from A where name = '李四';

(2)select NO,NAME,ID from A,B where A.NO = B.NO AND DEPOSIT >= 1000;

(3)select COUNTRY,count(*) FROM A GROUP BY COUNTRY;

(4)SELECT '80 后' as 年龄段,sum(CREDIT) AS '信用卡余额' FROM A,B WHERE A.NO = B.NO AND BIRTH >= 19800101 AND BIRTH < 19900101

UNION

SELECT '90 后' as 年龄段,sum(CREDIT) AS '信用卡余额' FROM A,B WHERE A.NO = B.NO AND BIRTH >= 19900101 AND BIRTH < 20000101;

3、数据库(编写示例 sql)

答案:

select orderNo, if(status=1,'新建','处理中') from OrderTrans;

select DATE_FORMAT(a.crttime,'%m-%d-%Y') ,username,count(*) from testCase a,User b where a.crtUser = b.UserId group by DATE_FORMAT(a.crttime,'%m-%d-%Y'),b.username, having status = '成功';

select count(*),sum(amount),DATE_FORMAT(crttime,'%m-%d-%Y') from OrderInfo group by

DATE_FORMAT(crttime,'%m-%d-%Y');

4、现有三张数据表如下:学生资料表:记录学生基本信息;课程表:记录课程基本信息;成绩表:记录每人各门课程成绩的信息,1 个学生对应多个成绩,1 个成绩只属于一个学生,一个课程

答案:

Select * from students where jg = ‘湖北’ and birthday = ‘1992-6-1’ order by no asc;

Select avg(so.cj),min(so.cj),max(so.cj),sum(so.cj) from student st,course c,source so where st.no = so.no and c.kebh=so.kebh and st.name = ‘王华’ group by st.no;

Select st.no,st.name,st.bj,c.kebh,c.kcmc,so.cj from student st,course c,source so where st.no = so.no and c.kebh=so.kebh and st.name = ‘张三’ order by so.cj desc;

答案:

Select Consultant.SubsidiaryID, BaseOrder.* from Consultant, BaseOrder where Consultant.ConsultantID = BaseOrder.ConsultantID and Consultant.SubsidiaryID = 29 order by Orderid desc;

Select BaseOrder.ConsultantID,sum(OrderDetails.TotalPrice) from BaseOrder,OrderDetails where BaseOrder.Orderid=OrderDetails.Orderid and month(OrderDate) = 5 group by BaseOrder.ConsultantID;

Insert into Consultant (ConsultantID,ConstultantStatusID,SubsidiaryID,Name) values (200000,10,29,’Gary’);

Delete from Consultant where Name like ‘%Gary%’;

Update BaseOrder set OrderDate = sysdate() where ConsultantID in (select ConsultantID from BaseOrder where ConsultantID=100003 order by OrderDate desc limit 0,1);

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 第 第1 章 数据库章节1.1 选择1.1.1 Having 子句的作用是(C) 。A.查询结果的分组条件 B.组...
    亮仔_c1b5阅读 1,943评论 0 0
  • //文章表 文章标题(title)、文章内容(content)、文章点击量(hits)、文章评论量(coms) c...
    红颜心雨阅读 407评论 0 0
  • (一)Oracle数据库 1.oracle中row_id理解 ORACLE的row_id是一个伪列,其个是为18个...
    独云阅读 5,736评论 0 10
  • 补充:题目描述查找所有员工自入职以来的薪水涨幅情况,给出员工编号emp_no以及其对应的薪水涨幅growth,并按...
    thuglife715阅读 305评论 0 0
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,870评论 0 10

友情链接更多精彩内容