经典 SQL 数据库笔试题及答案整理
马上又是金九银十啦,有蛮多小伙伴在跳槽找工作,但对于年限稍短的软件测试工程师,难免会必要进行笔试,而在笔试中,根本都会碰到一道关于数据库的大题,今天这篇文章呢,就收录了下最近学员反馈上来的一些数据库笔试题,包罗答案!1、依据以下学生表、班级表,按要求写 SQL
https://i-blog.csdnimg.cn/blog_migrate/120af838c7fb4760a9d591a92477d695.png
答案:
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
https://i-blog.csdnimg.cn/blog_migrate/b991d537af629e26772ce0d6811c8a69.png
答案:
(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)
https://i-blog.csdnimg.cn/blog_migrate/40aac08887a93b07c0abf8ebaf8a5dbc.png
https://i-blog.csdnimg.cn/blog_migrate/7745cd94365566279265b549bb72f78e.png
答案:
[*]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 个效果只属于一个学生,一个课程
https://i-blog.csdnimg.cn/blog_migrate/46d3111fefc50650df4acbea3cfe3336.png
答案:
[*]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;
5、有三张表 Contacts 库 Consultant 表、Basket 库 BaseOrder 表、Basket 库 OrderDetails 表,按要求写 SQL
https://i-blog.csdnimg.cn/blog_migrate/f444fd32d593c098b23772cb3bb803f9.png
https://i-blog.csdnimg.cn/blog_migrate/0b979b682eb830e6af766501a35b746e.png
答案:
[*]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);
最后: 下方这份完整的软件测试视频教程已经整理上传完成,必要的朋侪们可以自行领取【包管100%免费】
https://img-blog.csdnimg.cn/direct/5fee8dc352da4308ad6f5b74a93e00ff.png
https://img-blog.csdnimg.cn/direct/548739300f9a4319ad70f9f274c40952.gif
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]