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;
相关推荐
漫步者TZ10 分钟前
【StarRocks系列】事务
数据库·starrocks·事务
远方160918 分钟前
57-Oracle SQL Profile(23ai)实操
大数据·数据库·sql·oracle·database
钟琛......20 分钟前
MySQL 慢 SQL 识别与优化
java·数据库·sql·mysql
海天胜景24 分钟前
sqlsuger 获取表行数
数据库
Code季风25 分钟前
SQL关键字三分钟入门:INSERT INTO —— 插入数据详解
数据库·sql·oracle
陈卓4101 小时前
MySQL存储引擎与架构
数据库·mysql·架构
星辰离彬1 小时前
MySQL复杂查询优化实战:从多表关联到子查询的性能突破
数据库·后端·sql·mysql·性能优化
AA-代码批发V哥1 小时前
MySQL之InnoDB存储引擎深度解析
数据库·mysql
远方16099 小时前
53-Oracle sqlhc多版本实操含(23 ai)
大数据·数据库·sql·oracle·database