经典 SQL 数据库笔试题及答案整理

article/2025/9/30 3:28:06

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

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);

ps:小编个人收集啦许多软测资料,希望能够帮到学软件测试的朋友们软件资料分享包括但不限于:Java自动化测试、Python自动化测试、性能测试、web测试、APP测试

测试开发工具包:appuim安装包、fiddler安装包(也有配套视频教程)、eclipse、git、jmeter、loadrunner、monkey、postman、soapul、Xmind等等

有需要的朋友可以点击链接领取

软件测试全套基础/进阶/转行资料
 


http://chatgpt.dhexx.cn/article/hOmVXvLQ.shtml

相关文章

AttributeUsage(转载)

System.AttributeUsage声明一个Attribute的使用范围与使用原则。 AllowMultiple 和 Inherited 参数是可选的&#xff0c;所以此代码具有相同的效果&#xff1a; AttributeTarget的值可以参考1。部分可取值如下&#xff1a; 如果 AllowMultiple 参数设置为 true&#xff0c;则返…

[AttributeUsage(AttributeTargets.Class)] 用法例子

首先,创建一个自定义的Attribute,并且事先设定我们的Attribute将施加在class的元素上面以获取一个类代码的检查信息。 using System; using System.Reflection; [AttributeUsage(AttributeTargets.Class)] public class CodeReviewAttribute : System.Attribute //定义一个Co…

介绍属性与自定义属性、AttributeUsage

介绍属性 属性为访问自定义类型的注释信息提供通用的访问方式。注释信息是随意的&#xff0c;换句话说&#xff0c;这种信息不是语言自身固有的&#xff0c;而是由你自己能够想象到的任何信息。你能使用属性&#xff08;attributes&#xff09;定义设计时信息&am…

理解AttributeUsage类

类定义&#xff1a; // 摘要: // 指定另一特性类的用法。 此类不能被继承。[Serializable][AttributeUsage(AttributeTargets.Class, Inherited true)][ComVisible(true)]public sealed class AttributeUsageAttribute : Attribute{// 摘要: // 用指定的 System.Attri…

AttributeUsage属性

除了定制 attributes 之外&#xff0c;可以使用 Attributes 属性定义如何使用这些属性。例如&#xff1a;<?xml:namespace prefix o ns "urn:schemas-microsoft-com:office:office" /> [AttributeUsage( validon, AllowMultiple allowmultiple, …

AttributeUsage

AttributeUsage 【AttributeUsage】 System.AttributeUsage声明一个Attribute的使用范围与使用原则。 AllowMultiple 和 Inherited 参数是可选的&#xff0c;所以此代码具有相同的效果&#xff1a; AttributeTarget的值可以参考1。部分可取值如下&#xff1a; 如果 AllowMultip…

吉大软构件和中间件课程-JPA配置方法

吉大软构件和中间件课程-JPA配置方法 JPA连接方法&#xff1a; 1.standalone.xml 文字&#xff1a; <xa-datasource jta"true" jndi-name"java:jboss/datasources/MySqlDS" pool-name"MySqlDS" enabled"true" use-java-c…

JPA 配置文件最详细总结,没有之一!

又来了一个懵懂少年&#xff0c;看我怎么骗你的。 来我们开始学习吧。 PropertyPlaceholderConfigure 载入属性文件&#xff1a; 例如&#xff1a;class"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><propertyname"loc…

Spring Boot使用spring-data-jpa配置Mysql多数据源

转载请注明出处 :Spring Boot使用spring-data-jpa配置Mysql多数据源 我们在之前的文章中已经学习了Spring Boot中使用mysql数据库 在单数据源的情况下&#xff0c;Spring Boot的配置非常简单&#xff0c;只需要在application.properties文件中配置连接参数即可。 但是往往随…

SpringBoot 配置 JPA

新建项目 在application.properties配置文件中进行配置&#xff08;或者application.yaml中配置也行&#xff09; spring.datasource.urljdbc:mysql://localhost:3306/ssm?characterEncodingutf8&useSSLfalse&serverTimezoneUTC spring.datasource.usernameroot sp…

Springboot---JPA配置

1.在配置文件中写入数据库信息 application.properties配置如下 spring.datasource.primary.urljdbc:mysql://localhost:3306/test1 spring.datasource.primary.usernameroot spring.datasource.primary.passwordroot spring.datasource.primary.driver-class-namecom.mysql.…

spring-boot-starter-data-jpa 配置多个数据源与jpa实体类继承的问题、分页条件查询

JPA的继承注解一般有四种 MappedSuperclass 这个注解应用的场景是父类不对应任何单独的表&#xff0c;多个子类共用相同的属性。 注意&#xff1a; MappedSuperclass注解使用在父类上面&#xff0c;是用来标识父类的作用 MappedSuperclass标识的类表示其不能映射到数据库表&am…

Springboot多数据源+Jpa配置

随着业务复杂程度的增加&#xff0c;单一数据源越来越不满足具体的业务逻辑以及实现。 这里我用到了MySQL和Presto两种数据源&#xff1a; 多数据源配置GlobalDataSourceConfiguration&#xff1a; Configuration public class GlobalDataSourceConfiguration {Bean(name …

springboot--jpa 配置多数据库

使用spring boot jpa 配置多数据源 由于项目整合 以前的功能 但是以前功能存储的数据库是另一个数据库 这两天搜索了一下 遇见了许多坑 在这里记录一下 首先附上我的项目结构 可能有些乱 忘见谅。 pom.xml(把数据库的依赖引入) <!-- mariadb --><dependen…

Spring Data Jpa 配置多数据源

文章目录 1.配置数据库连接信息2.编写数据源配置类3.编写数据库配置4.目录结构 1.配置数据库连接信息 spring:datasource:db1: # 1.0 Datasourceurl: jdbc:mysql://127.0.0.1:3306/test1?useSSLfalse&serverTimezoneGMT%2b8&characterEncodingutf8&connectTimeo…

springboot2+JPA 配置多数据源(不同类型数据库)

注意&#xff1a;看此篇文章之前&#xff0c;springbootjpa的配置环境应搭建好&#xff0c;不会搭可以自行百度。本文章主要讲述配置JPA多数据源。 1.数据源配置文件 application.properties # 数据源thirded&#xff08;oracle数据库&#xff09; spring.jpa.thirded.databa…

jpa配置(jpa配置连接池)

JPA的实体状态有哪些呢&#xff1f; 该接口拥有众多执行数据查询的接口方法&#xff1a; Object getSingleResult()&#xff1a;执行SELECT查询语句&#xff0c;并返回一个结果&#xff1b; List getResultList() &#xff1a;执行SELECT查询语句&#xff0c;并返回多个结果&…

SpringBoot系列之数据库初始化-jpa配置方式

上一篇博文介绍如何使用spring.datasource来实现项目启动之后的数据库初始化&#xff0c;本文作为数据库初始化的第二篇&#xff0c;将主要介绍一下&#xff0c;如何使用spring.jpa的配置方式来实现相同的效果 I. 项目搭建 1. 依赖 首先搭建一个标准的SpringBoot项目工程&am…

Jpa环境配置及入门(增删改查)

案例&#xff1a;客户的相关操作&#xff08;增删改查&#xff09; 1.分析&#xff1a; 1.搭建环境&#xff1a; 创建maven工程&#xff0c;导入相关坐标&#xff1b; 配置使用jpa的核心配置文件&#xff1b; 位置&#xff1b;需要配置到类路径下叫做 META-INF的文件夹下 命…

PHP多国语言开发:CodeIgniter 2PHP框架中的多国语言,语言包(i18n)库

PHP多国语言开发&#xff1a;CodeIgniter 2PHP框架中的多国语言&#xff0c;语言包&#xff08;i18n&#xff09;多国语言库 引言 我们在CodeIgniter开发中经常会碰到多国语言网站&#xff0c;这里我们就来介绍一种简单有效的多国语言的操作方法。 做什么 语言在地址中是这…