1. 程式人生 > 其它 >SQL查閱筆記——多表查詢2

SQL查閱筆記——多表查詢2

-- 查詢工資高於豬八戒的員工資訊

select * from emp;

-- 1. 查詢豬八戒的工資
select salary from emp where name = '豬八戒';

-- 2. 查詢工資高於豬八戒的員工資訊
select * from emp where salary > 3600;

select * from emp where salary > (select salary from emp where name = '豬八戒');

 

子查詢根據查詢結果不同,作用不同。   1.單行單列:作為條件之,使用 = !><等進行條件判斷        select 欄位列表 from 表 where 欄位名 =(子查詢); 2.多行單列:作為條件值,使用in等關鍵字進行條件判斷   select 欄位列表 from 表 where 欄位名 in(子查詢); 3.多行多列 作為虛擬表 select 欄位列表 from (子查詢) where 條件;

-- 查詢 '財務部' 和 '市場部' 所有的員工資訊
-- 查詢 '財務部' 所有的員工資訊

select did from dept where dname = '財務部' or dname = '市場部';

select * from emp where dep_id in (select did from dept where dname = '財務部' or dname = '市場部');

-- 查詢入職日期是 '2011-11-11' 之後的員工資訊和部門資訊
-- 查詢入職日期是 '2011-11-11' 之後的員工資訊

select * from emp where join_date > '2011-11-11' ;


select * from (select * from emp where join_date > '2011-11-11' ) t1, dept where t1.dep_id = dept.did;