您当前的位置: 首页 >  sql

测试框架师凃九

暂无认证

  • 3浏览

    0关注

    118博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

花了三天三夜才收集整理出来的经典 SQL 数据库笔试题及答案

测试框架师凃九 发布时间:2022-08-31 21:52:54 ,浏览量:3

前言

金九银十期间,有蛮多小伙伴在跳槽找工作,但对于年限稍短的软件测试工程师,难免会需要进行笔试,而在笔试中,基本都会碰到一道关于数据库的大题,今天这篇文章呢,就是收集了一些小伙伴在面试中遇到的数据库的笔试题。

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)

答案:

  1. select orderNo, if(status=1,'新建','处理中') from OrderTrans;
  2. 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 = '成功';
  3. select count(*),sum(amount),DATE_FORMAT(crttime,'%m-%d-%Y') from OrderInfo group by DATE_FORMAT(crttime,'%m-%d-%Y');

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

答案:

  1. Select * from students where jg = ‘湖北’ and birthday = ‘1992-6-1’ order by no asc;
  2. 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;
  3. 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

答案:

  1. Select Consultant.SubsidiaryID, BaseOrder.* from Consultant, BaseOrder where Consultant.ConsultantID = BaseOrder.ConsultantID and Consultant.SubsidiaryID = 29 order by Orderid desc;
  2. Select BaseOrder.ConsultantID,sum(OrderDetails.TotalPrice) from BaseOrder,OrderDetails where BaseOrder.Orderid=OrderDetails.Orderid and month(OrderDate) = 5 group by BaseOrder.ConsultantID;
  3. Insert into Consultant (ConsultantID,ConstultantStatusID,SubsidiaryID,Name) values (200000,10,29,’Gary’);
  4. Delete from Consultant where Name like ‘%Gary%’;
  5. Update BaseOrder set OrderDate = sysdate() where ConsultantID in (select ConsultantID from BaseOrder where ConsultantID=100003 order by OrderDate desc limit 0,1);
总结

今天的文章就到这里了哟,需要获得下面福利的小伙伴可以私信我关键字“资料”获取哟。

喜欢的小伙伴不要忘记点赞收藏评论加关注哟。

关注
打赏
1662724262
查看更多评论
立即登录/注册

微信扫码登录

0.0385s