/*
語法: select
查詢列表
from
表名where
篩選條件;
分類: 一.按條件表示式篩選
> < = != >= <=
二. 邏輯表示式篩選 用於連線表示式
&& || !
and or not
三. 模糊查詢
like
between and
in is null
is not null
*/
select *
from employees
where salary>12000;
select last_name,department_id
from employees
where department_id!=90;
#工資在10000到20000之間的員工名,工資以及獎金
select
last_name,
salary,
commission_pct
from
employees
where
salary>=10000 and salary<=20000;
#部門編號不是在90-110 或者工資高於15000
select *
from employees
where not(department_id<90 or department_id>110) or salary>15000;
/*
like :
% 任意多個字元 包含0個字元
_ 任意單個字元
字元型或正數型都可
*/# 員工名字中帶a的
select *
from employees
where last_name like '%a%';
# 員工名字第三個字元為的e,第五個字元為a的員工名和工資
select *
from employees
where last_name like '__e_a%';
#員工名字第二個為_
select *
from employees
where last_name like '_\_%';
#查詢員工部門編號在100以上的
select *
from employees
where department_id like '1__';
select *
from employees
where last_name like '_$_%' escape '$';
/*
between and 區域 包含臨界值
*/select
last_name,
salary,
commission_pct
from
employees
where
salary between 10000 and 20000;
/*
in 型別必須一致 相當於=
*/select
last_name,
salary,
commission_pct,
job_id
from
employees
where
job_id in ('it_prot','ad_vp','ad_pres');
/*
is null
is not null
*/# 沒有獎金的員工名和獎金率
select last_name,commission_pct
from employees;
where commission_pct is null;
select last_name,commission_pct
from employees
where commission_pct is not null;
/*
安全等於<=>
null 或者普通值都可以判斷
*/select last_name,commission_pct
from employees;
where commission_pct <=>null;
select last_name,commission_pct
from employees
where commission_pct <=>0.1;
select last_name,department_id,salary*12*(1+ifnull(commission_pct,0)) as 年薪
from employees;
#練習select salary,last_name
from employees
where commission_pct is null and salary<18000;
#練習 jod_id 不為'it'
select *
from employees
where job_id != 'it' or salary<=>12000;
#練習 為null的全部沒有了
select *
from employees
where commission_pct like '%%';
Mysql基礎部分 3 條件查詢
mysql基礎部分內容 mysql基礎部分 1 基礎操作指令與語法規範 mysql基礎部分 2 基礎查詢 mysql基礎部分 3 條件查詢 mysql基礎部分 4 排序查詢 mysql基礎部分 5 常見函式 mysql基礎部分 6 分組函式 mysql基礎部分 7 分組查詢 mysql基礎部分 8 ...
02條件查詢 MySQL
條件查詢 語法 select 查詢列表 from 表明where 篩選條件 分類 一 按條件表示式刪選 條件運演算法 和 一樣 二 按邏輯表示式篩選 邏輯運算子 and or not 三 模糊查詢 萬用字元 代表任意多個字元,包括0個字元 代表乙個字元 注意 和 代表 和 like between ...
MySQL學習之路(四) 條件查詢
分類 按條件表示式篩選 簡單條件運算子 按邏輯表示式篩選 邏輯運算子 and or not 模糊查詢 like between and in is null is not nill select 列名1 列名2 from 表名 where 條件表示式select 列名1 列名2 from 表名 wh...