【SQL】SQL训练网站 SQLBlot
网站地址:
https://sqlbolt.com/
Lesson1:
-- https://sqlbolt.com/lesson/select_queries_introduction
-- Find the title of each film ✓
SELECT `TITLE ` FROM `movies`; -- Find the director of each film ✓
SELECT `DIRECTOR` FROM movies; -- Find the title and director of each film ✓
SELECT `TITLE`,`DIRECTOR` FROM movies; -- Find the title and year of each film ✓
SELECT `TITLE`,`YEAR` FROM movies; -- Find all the information about each film ✓
SELECT * FROM movies;
Lesson2:
-- https://sqlbolt.com/lesson/select_queries_with_constraints -- Find the movie with a row id of 6 ✓
SELECT * FROM movies WHERE `ID` = 6; -- Find the movies not released in the years between 2000 and 2010 ✓
SELECT * FROM movies WHERE `YEAR` BETWEEN 2000 AND 2010; -- Find the movies not released in the years between 2000 and 2010 ✓
SELECT `TITLE`, `YEAR` FROM movies WHERE `YEAR` < 2000 OR `YEAR` > 2010;
SELECT * FROM movies WHERE `YEAR` NOT BETWEEN 2000 AND 2010; -- Find the first 5 Pixar movies and their release year ✓
SELECT `TITLE`, `YEAR` FROM movies WHERE `YEAR` <= 2003;
Lesson3:
https://sqlbolt.com/lesson/select_queries_with_constraints_pt_2 -- Find all the Toy Story movies ✓
SELECT * FROM movies WHERE `TITLE ` LIKE '%Toy Story%'; -- Find all the movies directed by John Lasseter ✓
SELECT * FROM movies WHERE `DIRECTOR` = 'John Lasseter' -- Find all the movies (and director) not directed by John Lasseter ✓
SELECT * FROM movies WHERE `DIRECTOR` != 'John Lasseter' -- Find all the WALL-* movies ✓
SELECT * FROM movies WHERE `TITLE` LIKE '%WALL-%'
Lesson4:
-- https://sqlbolt.com/lesson/filtering_sorting_query_results -- List all directors of Pixar movies (alphabetically), without duplicates ✓
SELECT DISTINCT `DIRECTOR` FROM movies ORDER BY `DIRECTOR` -- List the last four Pixar movies released (ordered from most recent to least) ✓
SELECT * FROM movies ORDER BY `YEAR` DESC LIMIT 4 -- List the first five Pixar movies sorted alphabetically ✓
SELECT * FROM movies ORDER BY `TITLE` ASC LIMIT 5 -- List the next five Pixar movies sorted alphabetically ✓
SELECT * FROM movies ORDER BY `TITLE` ASC LIMIT 5, 5
Lesson5:
-- https://sqlbolt.com/lesson/select_queries_review -- List all the Canadian cities and their populations ✓
SELECT * FROM north_american_cities WHERE `COUNTRY` = 'Canada'; -- Order all the cities in the United States by their latitude from north to south ✓
SELECT * FROM north_american_cities
WHERE `COUNTRY` = 'United States'
ORDER BY `LATITUDE` DESC; -- List all the cities west of Chicago, ordered from west to east ✓
SELECT `CITY`,`LONGTITUDE` FROM north_american_cities
WHERE `LONGTITUDE` < -87.629798
ORDER BY `LONGTITUDE` ASC; -- List the two largest cities in Mexico (by population) ✓
SELECT * FROM north_american_cities
WHERE `COUNTRY` = 'Mexico'
ORDER BY `POPULATION` DESC LIMIT 2 -- List the third and fourth largest cities (by population) in the United States and their population ✓
SELECT * FROM north_american_cities
WHERE `COUNTRY` = 'United States'
ORDER BY `POPULATION` DESC LIMIT 2, 2
Lesson6:
-- https://sqlbolt.com/lesson/select_queries_with_joins -- Find the domestic and international sales for each movie ✓
SELECT
A.*,
B.`DOMESTIC_SALES`,
B.`INTERNATIONAL_SALES`
FROM
movies AS A
JOIN `boxoffice` AS B ON A.ID = B.MOVIE_ID; -- Show the sales numbers for each movie that did better internationally rather than domestically ✓
SELECT `title`, `domestic_sales`, `international_sales`
FROM
`MOVIES` AS A
JOIN `BOXOFFICE` AS B ON A.id = B.movie_id
WHERE B.`international_sales ` > B.`domestic_sales`; -- List all the movies by their ratings in descending order ✓
SELECT A.`title`, B.`rating`
FROM
`movies` AS A
JOIN `boxoffice` AS B ON movies.id = boxoffice.movie_id
ORDER BY rating DESC;
Lesson7:
-- https://sqlbolt.com/lesson/select_queries_with_outer_joins -- Find the list of all buildings that have employees ✓
SELECT DISTINCT building FROM employees; -- Find the list of all buildings and their capacity ✓
SELECT * FROM Buildings -- List all buildings and the distinct employee roles in each building (including empty buildings) ✓
SELECT DISTINCT A.`building_name`, B.`role `
FROM
buildings AS A
LEFT JOIN employees AS B ON A.building_name = B.building;
Lesson8:
-- https://sqlbolt.com/lesson/select_queries_with_nulls -- Find the name and role of all employees who have not been assigned to a building ✓
SELECT * FROM Employees WHERE Building IS NULL -- Find the names of the buildings that hold no employees ✓
SELECT
A.Building_name
FROM
Buildings AS A
LEFT JOIN Employees AS B ON A.Building_name = B.Building
WHERE
B.Building IS NULL
Lesson9:
-- https://sqlbolt.com/lesson/select_queries_with_expressions -- List all movies and their combined sales in millions of dollars ✓
SELECT
A.title,
(domestic_sales + international_sales) / 1000000 AS gross_sales_millions
FROM
movies AS A,
JOIN boxoffice AS B ON A.id = B.movie_id; -- List all movies and their ratings in percent ✓
SELECT
A.TITLE,
B.RATING * 10 AS rating_percent
FROM
movies AS A
JOIN Boxoffice AS B ON A.ID = B.MOVIE_ID -- List all movies that were released on even number years ✓
SELECT title, year
FROM movies
WHERE year % 2 = 0;
Lesson10:
-- https://sqlbolt.com/lesson/select_queries_with_aggregates -- Find the longest time that an employee has been at the studio ✓
SELECT * FROM employees ORDER BY Years_employed DESC LIMIT 1; -- For each role, find the average number of years employed by employees in that role ✓
SELECT ROLE, AVG(Years_employed) FROM Employees GROUP BY ROLE -- Find the total number of employee years worked in each building ✓
SELECT building, SUM(years_employed) as Total_years_employed
FROM employees
GROUP BY building;
Lesson11:
-- https://sqlbolt.com/lesson/select_queries_with_aggregates_pt_2 --Find the number of Artists in the studio (without a HAVING clause) ✓
SELECT ROLE, COUNT(NAME)
FROM employees
WHERE ROLE = 'Artist'
GROUP BY ROLE; SELECT role, COUNT(*) as Number_of_artists
FROM employees
WHERE role = "Artist"; -- Find the number of Employees of each role in the studio ✓
SELECT role, COUNT(*) as Number_of_artists
FROM employees
GROUP BY ROLE -- Find the total number of years employed by all Engineers ✓
SELECT SUM(Years_employed) FROM Employees WHERE ROLE = 'Engineer';
Lesson12:
-- https://sqlbolt.com/lesson/select_queries_order_of_execution -- Find the number of movies each director has directed ✓
SELECT Director,COUNT(*) FROM movies GROUP BY Director; -- Find the total domestic and international sales that can be attributed to each director ✓
SELECT
Director,
SUM(B.Domestic_sales + B.International_sales) AS Cumulative_sales_from_all_movies
FROM
Movies AS A
JOIN Boxoffice AS B ON A.ID = B.MOVIE_ID
GROUP BY A.Director
Lesson13:
-- https://sqlbolt.com/lesson/inserting_rows -- Add the studio's new production, Toy Story 4 to the list of movies (you can use any director) ✓
INSERT INTO Movies (Id, Title, Director, Year, Length_minutes) VALUES
(NULL, 'Toy Story 4', 'John Lasseter', NULL, NULL) -- Toy Story 4 has been released to critical acclaim! It had a rating of 8.7, and made 340 million domestically and 270 million internationally. Add the record to the BoxOffice table. ✓
INSERT INTO Boxoffice (Movie_id, Rating, Domestic_sales, International_sales) VALUES
(15, ' 8.7', 34000000, 27000000)
Lesson14:
-- https://sqlbolt.com/lesson/updating_rows -- The director for A Bug's Life is incorrect, it was actually directed by John Lasseter ✓
UPDATE `Movies`
SET DIRECTOR = 'John Lasseter'
WHERE TITLE = "A Bug's Life" -- The year that Toy Story 2 was released is incorrect, it was actually released in 1999 ✓
UPDATE `Movies`
SET YEAR = 1999
WHERE TITLE = 'Toy Story 2' -- Both the title and director for Toy Story 8 is incorrect! The title should be "Toy Story 3" and it was directed by Lee Unkrich ✓
UPDATE `Movies`
SET
DIRECTOR = 'Lee Unkrich',
TITLE = 'Toy Story 3'
WHERE TITLE = 'Toy Story 8'
Lesson15:
-- https://sqlbolt.com/lesson/deleting_rows -- This database is getting too big, lets remove all movies that were released before 2005. ✓
DELETE FROM movies WHERE YEAR < 2005; -- Andrew Stanton has also left the studio, so please remove all movies directed by him. ✓
DELETE FROM movies WHERE DIRECTOR = 'Andrew Stanton';
Lesson16:
-- https://sqlbolt.com/lesson/creating_tables -- Create a new table named Database with the following columns:
– Name A string (text) describing the name of the database
– Version A number (floating point) of the latest version of this database
– Download_count An integer count of the number of times this database was downloaded
This table has no constraints. CREATE TABLE `Database`(
NAME VARCHAR,
VERSION FLOAT,
Download_count INT
)
Lesson17:
-- Add a column named Aspect_ratio with a FLOAT data type to store the aspect-ratio each movie was released in. ✓
ALTER TABLE `Movies`
ADD COLUMN `Aspect_ratio` FLOAT DEFAULT 2.39 -- Add another column named Language with a TEXT data type to store the language that the movie was released in. Ensure that the default for this language is English. ✓
ALTER TABLE `Movies`
ADD COLUMN `Language` TEXT DEFAULT "English";
Lesson18:
-- https://sqlbolt.com/lesson/dropping_tables -- We've sadly reached the end of our lessons, lets clean up by removing the Movies table ✓
DROP TABLE `MOVIES`; -- And drop the BoxOffice table as well ✓
DROP TABLE `BOXOFFICE`;
【SQL】SQL训练网站 SQLBlot的更多相关文章
- [SQL]SQL类似统计功能的sql文
declare @t table(name varchar(),type int) insert into @t union all union all union all union all if ...
- pl/sql sql窗口允许输出和允许变量替换
pl/sql sql窗口允许输出和允许变量替换 允许输出:类似在命令窗口中输入的 setserveroutput on; 允许变量替换:如果点击了这个,类似于执行 set define off命令 在 ...
- 通过SQL注入获得网站后台用户密码
通过 SQL 注入攻击,掌握网站的工作机制,认识到 SQL 注入攻击的防范措施,加强对 Web 攻击的防范. 一.实验环境 下载所需代码及软件:获取链接:链接:https://pan.baidu.co ...
- SQL在线学习网站
1.在线编写网页:http://sqlfiddle.com/ 2.SQL菜鸟教程:http://www.runoob.com/sql/sql-intro.html 3.SQL语句在线练习 http:/ ...
- Java实战|Tomcat+Servlet+Sql开发简单网站,从配置环境开始
课题描述: Java实验五 Servlet (继续使用实验四中创建的students数据库和其中的scores表) 使用Tomcat作为Web服务器和Servlet容器,使用SQL Server/My ...
- 5cms使用sql语句给网站添加内容
<!--list:{$Sql=UPDATE [{pre}Content] SET Indexpic="/uploadfile/201405/25/lsgjyst.jpg",t ...
- oracle的sql语句训练
--查询工资最高的人的名字select ename ,sal from emp where sal=(select max(sal) from emp );--求出员工的工资在所有人的平均工资之上的人 ...
- [SQL] SQL学习笔记之基础操作
1 SQL介绍 SQL 是用于访问和处理数据库的标准的计算机语言.关于SQL的具体介绍,我们通过回答如下三个问题来进行. SQL 是什么? SQL,指结构化查询语言,全称是 Structured Qu ...
- [SQL]SQL语言入门级教材_SQL数据操作基础(二)
SQL数据操作基础(初级) netnova 于 -- :: 加贴在 数据库探讨: 为了建立交互站点,你需要使用数据库来存储来自访问者的信息.例如,你要建立一个职业介绍服务的站点,你就需要存储诸如个人简 ...
- [SQL] SQL 基础知识梳理(一)- 数据库与 SQL
SQL 基础知识梳理(一)- 数据库与 SQL [博主]反骨仔 [原文地址]http://www.cnblogs.com/liqingwen/p/5902856.html 目录 What's 数据库 ...
随机推荐
- Java中类的构造 与 方法的重载
类的构造方法 定义:构造方法与类名相同,且没有返回值,且不需要void修饰 Car bmcar = new Car(); 特点:类中没有定义时,会默认有一个无参的构造方法,在无参的构造方法中为成员变量 ...
- Math Record
T1.P3327 知识点:莫比乌斯反演,数论分块 我们知道 \(d(ij) = \sum_{x | i}\sum_{y | j}[\gcd(x,y) == 1]\). 所以我们就要求 \(\sum^n ...
- 使用极限网关助力 ES 集群无缝升级、迁移上/下云
在工作中大家可能会遇到以下这些场景: 自建 ES 集群需要平滑迁移到 XX 云: 从 XX 云将 ES 集群迁移到自建机房: ES 集群进行跨版本升级,同时保留回退能力: 这些场景往往都还有个共同的需 ...
- 使用 OpenTelemetry 构建可观测性 06 - 生态系统
过去的五篇文章讨论了如何使用 OpenTelemetry 来构建可观测性的技术细节.我认为在本博文系列的结尾介绍有关 OTel 生态系统的信息,为读者提供更全面的了解非常重要.OpenTelemetr ...
- 可观测性平台夜莺开源项目发布V6正式版!
夜莺开源项目在2023.7月底发布了V6版本,这个版本开始,项目目标不止于做一款开源监控系统,而是要做一款开源可观测性平台,不过路漫漫其修远兮,初期只是把日志数据源引入并完成了基本的可视化,后续会着力 ...
- leetcode-3-无重复字符的最长子串-javascript
题目 给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度. 示例 1: 输入: "abcabcbb" 输出: 3 解释: 因为无重复字符的最长子串是 "abc ...
- kettle从入门到精通 第七十一课 ETL之kettle 再谈http post,轻松掌握body中传递json参数
场景: kettle中http post步骤如何发送http请求且传递body参数? 解决方案: http post步骤中直接设置Request entity field字段即可. 1.手边没有现成的 ...
- 2024年软件架构趋势之AI与机器学习的关系
在当下这个信息爆炸的时代,我们经常会听到"AI"和"机器学习"这两个词.它们似乎总是携手出现,让人觉得它们就是一对不可分割的"好基友".但你 ...
- spring与设计模式之四适配器模式
一.定义 适配器模式-或者称为转接口模式,变压器模式.通过适配,可以让原来提供特定功能的对象完成另外一个标准的功能. 所以,所谓的适配应该可以这样称呼:让某些类/接口适配/转换某个标准/功能. 适配器 ...
- 2019 南昌区域赛 CEGLM 题解 & lagrange 插值
B. A Funny Bipartite Graph 状压 dp ,利用了原题中选完左边点集,那么右边在 左边编号最大的那个数 之前的所有点都要选的性质,可以优化到 \(O(n \cdot 2^n)\ ...