SQL语句练习 自学SQL网 多表查询

目录

[Day 6 用JOINs进行多表联合查询](#Day 6 用JOINs进行多表联合查询)

[Day 7 外连接 OUTER JOINs](#Day 7 外连接 OUTER JOINs)

[Day 8 外连接 特殊关键字 NULLs](#Day 8 外连接 特殊关键字 NULLs)


Day 6 用JOINs进行多表联合查询

复制代码
SELECT *  FROM Boxoffice 
   		  INNER JOIN movies 
          ON movies.id=boxoffice.Movie_id;

SELECT * FROM Boxoffice 
	      INNER JOIN movies
          ON movies.id=boxoffice.Movie_id
          WHERE Domestic_sales<International_sales;

SELECT * FROM Boxoffice
  		  INNER JOIN movies
          ON movies.id=boxoffice.Movie_id
          ORDER BY Rating ASC

SELECT Director , International_sales FROM Boxoffice   
 	      INNER JOIN movies
          on movies.id=boxoffice.Movie_id
          ORDER BY International_sales DESC 
          LIMIT 1 OFFSET 0;
          
SELECT Director , International_sales FROM Boxoffice 
			INNER JOIN movies
            ON movies.id=boxoffice.Movie_id
            ORDER BY International_sales DESC
            LIMIT 1 OFFSET 0;

Day 7 外连接 OUTER JOINs

复制代码
SELECT DISTINCT Building_name FROM buildings 
		LEFT JOIN employees  
        WHERE employees.Building=buildings .Building_name
  
SELECT DISTINCT Role ,Building_name FROM buildings 
		LEFT JOIN employees   
        on employees.Building=buildings .Building_name;
        
SELECT DISTINCT Building ,Capacity FROM buildings 
		LEFT JOIN employees
        ON employees .Building = buildings.Building_name
        WHERE Building is not null;

Day 8 外连接 特殊关键字 NULLs

·

复制代码
SELECT Role ,Name FROM employees
	   WHERE Building IS NULL;

select * FROM Buildings
		LEFT JOIN Employees
		ON Buildings.Building_name = Employees.Building	
		WHERE name is null;
相关推荐
苹果酱05671 小时前
Java设计模式:探索编程背后的哲学
java·vue.js·spring boot·mysql·课程设计
五花肉村长1 小时前
Linux-读者写著问题和读写锁
linux·运维·服务器·开发语言·数据库·visualstudio
五步晦暝3 小时前
【Excel 支持正则的方法】解决VBA引入正则的方法和步骤
数据库·mysql·excel
卡戎-caryon3 小时前
【MySQL】07.表内容的操作
linux·网络·数据库·mysql·存储引擎
一只fish3 小时前
MySQL 8.0 OCP 1Z0-908 题目解析(11)
数据库·mysql
麓殇⊙4 小时前
黑马点评--基于Redis实现共享session登录
数据库·redis·firefox
zhutoutoutousan4 小时前
解决 Supabase “permission denied for table XXX“ 错误
javascript·数据库·oracle·个人开发
泽韦德4 小时前
【MySQL】第8节|Innodb底层原理与Mysql日志机制深入剖析(一)
数据库·mysql
vvilkim4 小时前
MongoDB 数据库迁移:完整指南与最佳实践
数据库·mongodb
vvilkim4 小时前
MongoDB索引:原理、实践与优化指南
数据库·mongodb