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;
相关推荐
-SGlow-2 小时前
MySQL相关概念和易错知识点(2)(表结构的操作、数据类型、约束)
linux·运维·服务器·数据库·mysql
新world2 小时前
mybatis-plus从入门到入土(三):持久层接口之IService
mybatis
明月5663 小时前
Oracle 误删数据恢复
数据库·oracle
水瓶_bxt4 小时前
Centos安装HAProxy搭建Mysql高可用集群负载均衡
mysql·centos·负载均衡
♡喜欢做梦4 小时前
【MySQL】深入浅出事务:保证数据一致性的核心武器
数据库·mysql
遇见你的雩风4 小时前
MySQL的认识与基本操作
数据库·mysql
dblens 数据库管理和开发工具4 小时前
MySQL新增字段DDL:锁表全解析、避坑指南与实战案例
数据库·mysql·dblens·dblens mysql·数据库连接管理
weixin_419658314 小时前
MySQL的基础操作
数据库·mysql
不辉放弃5 小时前
ZooKeeper 是什么?
数据库·大数据开发
Goona_6 小时前
拒绝SQL恐惧:用Python+pyqt打造任意Excel数据库查询系统
数据库·python·sql·excel·pyqt