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

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

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

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

1.运行一下

在这里插入图片描述

2.等待加载

3.在网页打开

在这里插入图片描述

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

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

练习

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 1
    from class
    where 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;

原文地址:https://blog.csdn.net/m0_73756108/article/details/134808248

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_49076.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注