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;
相关推荐
枫叶200016 分钟前
OceanBase数据库-学习笔记4-租户
数据库·笔记·学习·oceanbase
辰哥单片机设计2 小时前
LCD1602液晶显示屏详解(STM32)
数据库·mongodb
夜光小兔纸3 小时前
SQL Server 数据库重命名
运维·数据库·sql server
red_redemption3 小时前
Spring Boot + MyBatis-Plus 的现代开发模式
java·spring boot·mybatis
苹果酱05673 小时前
iview内存泄漏
java·vue.js·spring boot·mysql·课程设计
maomi_95264 小时前
Mysql之数据库基础
数据库·mysql
XY.散人4 小时前
初识Redis · 分布式锁
数据库·redis·分布式
Elastic 中国社区官方博客4 小时前
Elasticsearch:没有 “AG” 的 RAG?
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
镜舟科技4 小时前
大数据平台与数据仓库的核心差异是什么?
starrocks·数据仓库·数据湖·大数据平台·湖仓一体·物化视图·流式湖仓