sql-SQL练习生

2023-12-11 19:30
文章标签 sql database 练习生

本文主要是介绍sql-SQL练习生,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

推荐一款inscode内的模板SQL练习生,此文附带目前所有题的答案
如有错误欢迎斧正~

https://inscode.csdn.net/@TPEngineer/SQLBoy

为了更好的体验,请按下面的方法打开:

1.运行一下

在这里插入图片描述

2.等待加载

3.在网页打开

在这里插入图片描述

温馨提醒:此处做题不会保存进度,请自行记录做题情况

个人总结的答案(已涵盖目前的所有题,题库更新踢我)

文章目录

      • 练习
        • 1.基础语法 - 查询 - 全表查询
        • 2.基础语法 - 查询 - 选择查询
      • 主线关卡
        • 1.基础语法 - 查询 - 全表查询
        • 2.基础语法 - 查询 - 选择查询
        • 3.基础语法 - 查询 - 别名
        • 4.基础语法 - 查询 - 常量和运算
        • 5.基础语法 - 条件查询 - where
        • 6.基础语法 - 条件查询 - 运算符
        • 7.基础语法 - 条件查询 - 空值
        • 8.基础语法 - 条件查询 - 模糊查询
        • 9.基础语法 - 条件查询 - 逻辑运算
        • 10.基础语法 - 去重
        • 11.基础语法 - 排序
        • 12.基础语法 - 截断和偏移
        • 13.基础语法 - 条件分支
        • 14.函数 - 时间函数
        • 15.函数 - 字符串处理
        • 16.函数 - 聚合函数
        • 17.分组聚合 - 单字段分组
        • 18.分组聚合 - 多字段分组
        • 19.分组聚合 - having 子句
        • 20.查询进阶 - 关联查询 - cross join
        • 21.查询进阶 - 关联查询 - inner join
        • 22.查询进阶 - 关联查询 - outer join
        • 23.查询进阶 - 子查询
        • 24.查询进阶 - 子查询 - exists
        • 25.查询进阶 - 组合查询
        • 26.查询进阶 - 开窗函数 - sum over
        • 27.查询进阶 - 开窗函数 - sum over order by
        • 28.查询进阶 - 开窗函数 - rank
        • 29.查询进阶 - 开窗函数 - row_number
        • 30.查询进阶 - 开窗函数 - lag / lead
      • 自定义关卡
        • 冒险者和金币
        • 魔法学院
        • 大浪淘鸡

练习

1.基础语法 - 查询 - 全表查询
-- 请在此处输入 SQL
select * from student;
2.基础语法 - 查询 - 选择查询
-- 请在此处输入 SQL
select name,age from student;

主线关卡

1.基础语法 - 查询 - 全表查询
-- 请在此处输入 SQL
select * from student;
2.基础语法 - 查询 - 选择查询
-- 请在此处输入 SQL
select name,age from student;
3.基础语法 - 查询 - 别名
-- 请在此处输入 SQL
select name as 学生姓名,
age as 学生年龄
from student;
4.基础语法 - 查询 - 常量和运算
-- 请在此处输入 SQL
select name,score,2*score as double_score from student;
5.基础语法 - 条件查询 - where
-- 请在此处输入 SQL
select name,score 
from student
where name='鱼皮';
6.基础语法 - 条件查询 - 运算符
-- 请在此处输入 SQL
select name,age 
from student
where name!='热dog'
7.基础语法 - 条件查询 - 空值
-- 请在此处输入 SQL
select name,age,score 
from student
where age is not null;
8.基础语法 - 条件查询 - 模糊查询
-- 请在此处输入 SQL
select name,score 
from student
where name not like '%李%';
9.基础语法 - 条件查询 - 逻辑运算
-- 请在此处输入 SQL
select name,score 
from student
where name like '%李%'  or score>500;
10.基础语法 - 去重
-- 请在此处输入 SQL
select distinct class_id,exam_num 
from student;
11.基础语法 - 排序
-- 请在此处输入 SQL
select name,age,score 
from student
order by score desc,
age asc;
12.基础语法 - 截断和偏移
-- 请在此处输入 SQL
select name,age from student
order by age asc
limit 1,3;
13.基础语法 - 条件分支
-- 请在此处输入 SQL
select name,case when (age>60) then '老同学'when (age>20) then '年轻'else '小同学' end as age_level
from student
order by name asc;
14.函数 - 时间函数
-- 请在此处输入 SQL
select name,
date() as '当前日期' 
from student;
15.函数 - 字符串处理
-- 请在此处输入 SQL
select id ,
name ,
upper(name) as upper_name 
from student where name=='热dog';
16.函数 - 聚合函数
-- 请在此处输入 SQL
select sum(score) as total_score,
AVG(score) as avg_score,
MAX(score) as max_score,
MIN(score) as min_score from student;
17.分组聚合 - 单字段分组
-- 请在此处输入 SQL
select class_id,
AVG(score) as avg_score 
from student 
group by class_id;
18.分组聚合 - 多字段分组
-- 请在此处输入 SQL
select class_id,
exam_num,
Count(id) as total_num 
from student 
group by class_id,exam_num;
19.分组聚合 - having 子句
-- 请在此处输入 SQL
select class_id,
SUM(score) as total_score 
from student
group by class_id
having SUM(score)>150;
20.查询进阶 - 关联查询 - cross join
-- 请在此处输入 SQL
select s.name as student_name,
s.age as student_age,
s.class_id as class_id,
c.name as class_name
from student s 
cross join
class c;
21.查询进阶 - 关联查询 - inner join
-- 请在此处输入 SQL
select s.name as student_name,
s.age as student_age,
s.class_id as class_id,
c.name as class_name,
c.level as class_level
from student s
join class c on s.class_id=c.id;
22.查询进阶 - 关联查询 - outer join
-- 请在此处输入 SQL
select s.name as student_name,
s.age as student_age,
s.class_id as class_id,
c.name as class_name,
c.level as class_level
from student s
left join class c
on s.class_id=c.id;
23.查询进阶 - 子查询
-- 请在此处输入 SQL
select s.name,s.score,s.class_id
from student s
where s.class_id IN (SELECT  c.id FROM class c);
24.查询进阶 - 子查询 - exists
-- 请在此处输入 SQL
select name,age,class_id 
from student
where not exists(select 1from classwhere class.id==student.class_id
);
25.查询进阶 - 组合查询
-- 请在此处输入 SQL
select name,age,score,class_id 
from student
union all
select name,age,score,class_id
from student_new;
26.查询进阶 - 开窗函数 - sum over
-- 请在此处输入 SQL
select id,name,age,score,class_id,
avg(score) over (partition by class_id)
as class_avg_score 
from student;
27.查询进阶 - 开窗函数 - sum over order by
-- 请在此处输入 SQL
select id,name,age,score,class_id,
sum(score) over (partition by class_id 
order by score asc)
as class_sum_score
from student;
28.查询进阶 - 开窗函数 - rank
-- 请在此处输入 SQL
select id,name,age,score,class_id,
rank() over 
(partition by class_id order by score desc)
as ranking
from student;
29.查询进阶 - 开窗函数 - row_number
-- 请在此处输入 SQL
select id,name,age,score,class_id,
row_number() over
(partition by class_id order by score desc)
as row_number
from student;
30.查询进阶 - 开窗函数 - lag / lead
-- 请在此处输入 SQL
select id,name,age,score,class_id,
lag(name,1,null) over 
(partition by class_id order by score desc)
as prev_name,
lead(name,1,null) over 
(partition by class_id order by score desc)
as next_name
from student;

自定义关卡

冒险者和金币
-- 请在此处输入 SQL
select adventurer_id,adventurer_name,
sum(reward_coins) as total_reward_coins
from rewards
group by adventurer_id,adventurer_name
order by total_reward_coins desc
limit 3;
魔法学院
-- 请在此处输入 SQL
select student_id,student_name,subject_id,subject_name,score,
rank() over (partition by subject_id order by score desc)
as score_rank
from magic_scores;
大浪淘鸡
-- 请在此处输入 SQL
select observer_name,observation_date,wave_intensity from chicken_observation
where observation_location like '%大浪淘鸡%'
and wave_intensity >5;

这篇关于sql-SQL练习生的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/481856

相关文章

SQL server数据库如何下载和安装

《SQLserver数据库如何下载和安装》本文指导如何下载安装SQLServer2022评估版及SSMS工具,涵盖安装配置、连接字符串设置、C#连接数据库方法和安全注意事项,如混合验证、参数化查... 目录第一步:打开官网下载对应文件第二步:程序安装配置第三部:安装工具SQL Server Manageme

C#连接SQL server数据库命令的基本步骤

《C#连接SQLserver数据库命令的基本步骤》文章讲解了连接SQLServer数据库的步骤,包括引入命名空间、构建连接字符串、使用SqlConnection和SqlCommand执行SQL操作,... 目录建议配合使用:如何下载和安装SQL server数据库-CSDN博客1. 引入必要的命名空间2.

全面掌握 SQL 中的 DATEDIFF函数及用法最佳实践

《全面掌握SQL中的DATEDIFF函数及用法最佳实践》本文解析DATEDIFF在不同数据库中的差异,强调其边界计算原理,探讨应用场景及陷阱,推荐根据需求选择TIMESTAMPDIFF或inte... 目录1. 核心概念:DATEDIFF 究竟在计算什么?2. 主流数据库中的 DATEDIFF 实现2.1

MySQL 多列 IN 查询之语法、性能与实战技巧(最新整理)

《MySQL多列IN查询之语法、性能与实战技巧(最新整理)》本文详解MySQL多列IN查询,对比传统OR写法,强调其简洁高效,适合批量匹配复合键,通过联合索引、分批次优化提升性能,兼容多种数据库... 目录一、基础语法:多列 IN 的两种写法1. 直接值列表2. 子查询二、对比传统 OR 的写法三、性能分析

MySQL中的LENGTH()函数用法详解与实例分析

《MySQL中的LENGTH()函数用法详解与实例分析》MySQLLENGTH()函数用于计算字符串的字节长度,区别于CHAR_LENGTH()的字符长度,适用于多字节字符集(如UTF-8)的数据验证... 目录1. LENGTH()函数的基本语法2. LENGTH()函数的返回值2.1 示例1:计算字符串

浅谈mysql的not exists走不走索引

《浅谈mysql的notexists走不走索引》在MySQL中,​NOTEXISTS子句是否使用索引取决于子查询中关联字段是否建立了合适的索引,下面就来介绍一下mysql的notexists走不走索... 在mysql中,​NOT EXISTS子句是否使用索引取决于子查询中关联字段是否建立了合适的索引。以下

Java通过驱动包(jar包)连接MySQL数据库的步骤总结及验证方式

《Java通过驱动包(jar包)连接MySQL数据库的步骤总结及验证方式》本文详细介绍如何使用Java通过JDBC连接MySQL数据库,包括下载驱动、配置Eclipse环境、检测数据库连接等关键步骤,... 目录一、下载驱动包二、放jar包三、检测数据库连接JavaJava 如何使用 JDBC 连接 mys

SQL中如何添加数据(常见方法及示例)

《SQL中如何添加数据(常见方法及示例)》SQL全称为StructuredQueryLanguage,是一种用于管理关系数据库的标准编程语言,下面给大家介绍SQL中如何添加数据,感兴趣的朋友一起看看吧... 目录在mysql中,有多种方法可以添加数据。以下是一些常见的方法及其示例。1. 使用INSERT I

Qt使用QSqlDatabase连接MySQL实现增删改查功能

《Qt使用QSqlDatabase连接MySQL实现增删改查功能》这篇文章主要为大家详细介绍了Qt如何使用QSqlDatabase连接MySQL实现增删改查功能,文中的示例代码讲解详细,感兴趣的小伙伴... 目录一、创建数据表二、连接mysql数据库三、封装成一个完整的轻量级 ORM 风格类3.1 表结构

MySQL 中的 CAST 函数详解及常见用法

《MySQL中的CAST函数详解及常见用法》CAST函数是MySQL中用于数据类型转换的重要函数,它允许你将一个值从一种数据类型转换为另一种数据类型,本文给大家介绍MySQL中的CAST... 目录mysql 中的 CAST 函数详解一、基本语法二、支持的数据类型三、常见用法示例1. 字符串转数字2. 数字