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;
相关推荐
oradh1 小时前
Oracle TX 锁 Mode 4(Share)问题排查总结
数据库·oracle·tx 锁 mode 4·oracle tx 锁
2601_962065252 小时前
[MySQL] SQL优化之性能分析
java·sql·mysql
yi.Ist2 小时前
数据定义语言-DDL操作
数据库·学习·mysql·oracle·大海豚
阿kun要赚马内2 小时前
MySQL 索引基础
后端·mysql
weixin_461408583 小时前
Mybatis-flex小记
java·开发语言·mybatis
2601_963282774 小时前
工程项目、政企采购为什么优先选择对讲机批量采购?
数据库
Doraemomo4 小时前
SQLite数据库
数据库·sqlite
2601_962177134 小时前
【MySQL篇】聚合查询,联合查询
android·java·mysql
云贝教育-郑老师4 小时前
MySQL 的“黑匣子“:Performance Schema 把数据库内部变成一张可查的表
数据库·mysql