MySQL练习

练习网址:https://sqlbolt.com/lesson/select_queries_introduction

SQL Lesson 6: Multi-table queries with JOINs
1. SELECT * FROM movies m JOIN Boxoffice b ON m.id = b.Movie_id
2. SELECT * FROM movies m JOIN Boxoffice b ON m.id = b.Movie_id WHERE International_sales > Domestic_sales
3. SELECT * FROM movies m JOIN Boxoffice b ON m.id = b.movie_id ORDER BY rating DESC

SQL Lesson 7: OUTER JOINs
1. SELECT DISTINCT building FROM Employees
2. SELECT * FROM Buildings
3. SELECT DISTINCT Building_name, Role FROM Buildings b LEFT JOIN Employees e ON b.building_name = e.building

SQL Lesson 8: A short note on NULLs
1. SELECT * FROM Employees WHERE Building IS NULL
2. SELECT DISTINCT * Building_name FROM Buildings b LEFT JOIN Employees e ON b.building_name = e.building WHERE Role IS NULL

SQL Lesson 9: Queries with expressions
1. SELECT Title,(Domestic_sales + International_sales) / 1000000 AS sales FROM Movies m JOIN Boxoffice b ON m.id = b.Movie_id
2. SELECT title, rating * 10 AS rating_percent FROM Movies m JOIN Boxoffice b ON m.id = b.Movie_id
3. SELECT title FROM movies WHERE Year % 2 = 0

SQL Lesson 10: Queries with aggregates (Pt. 1)
1. SELECT Years_employed FROM employees ORDER BY Years_employed DESC LIMIT 1
2. SELECT Role, AVG(Years_employed) FROM employees GROUP BY Role
3. SELECT Building,SUM(Years_employed) FROM employees GROUP BY Building

SQL Lesson 11: Queries with aggregates (Pt. 2)
1. SELECT COUNT(*) FROM employees WHERE Role = "Artist"
2. SELECT Role,COUNT(*) FROM employees GROUP BY Role
3. SELECT SUM(Years_employed) FROM employees WHERE Role = "Engineer"
 
SQL Lesson 12: Order of execution of a Query
1. SELECT Director,COUNT(*) FROM movies GROUP BY Director
2. SELECT Director,SUM(Domestic_sales + International_sales) FROM Movies m JOIN Boxoffice b ON m.Id = b.Movie_id GROUP BY Director

SQL Lesson 13: Inserting rows
1. INSERT INTO Movies VALUES (4, "Toy Story 4", "BOB", 2000, 88)
2. INSERT INTO Boxoffice VALUES (4, 8.7, 340000000, 270000000)

SQL Lesson 14: Updating rows
1. UPDATE Movies SET Director = "John Lasseter" WHERE id = 2
2. UPDATE Movies SET year = 1999 WHERE Title = "Toy Story 2"
3. UPDATE Movies SET Title = "Toy Story 3", Director = "Lee Unkrich" WHERE Title = "Toy Story 8"

SQL Lesson 15: Deleting rows
1. DELETE FROM movies WHERE Year < 2005
2. DELETE FROM movies WHERE Director = "Andrew Stanton"

SQL Lesson 16: Creating tables
1. CREATE TABLE Database (
    Name TEXT,
    Version FLOAT,
    Download_count INTEGER
)

SQL Lesson 17: Altering tables
1. ALTER TABLE Movies ADD COLUMN Aspect_ratio FLOAT
2. ALTER TABLE Movies ADD COLUMN Language TEXT DEFAULT "English"

SQL Lesson 18: Dropping tables
1. DROP TABLE Movies 
2. DROP TABLE BoxOffice


你可能感兴趣的:(mysql,数据库,sql)