案例1:查詢工資》12000的員工資訊
案例2:查詢部門編號不等於90號的員工名和部門編號select
*from
employees
where
salary>
12000
;
案例1:查詢工資z在10000到20000之間的員工名、工資以及獎金select
last_name,
department_id
from
employees
where
department_id<>
90;
案例2:查詢部門編號不是在90到110之間,或者工資高於15000的員工資訊select
last_name,
salary,
commission_pct
from
employees
where
salary>=
10000
and salary<=
20000
;
1.likeselect
*from
employees
where
not(department_id>=
90and department_id<=
110)
or salary>
15000
;
特點:
①一般和萬用字元搭配使用
萬用字元:
% 任意多個字元,包含0個字元
_ 任意單個字元
案例2:查詢員工名中第三個字元為e,第五個字元為a的員工名和工資#案例1:查詢員工名中包含字元a的員工資訊
select
*from
employees
where
last_name like
'%a%'
;
select
last_name,
salary
from
employees
where
last_name like
'__n_l%'
;
2.between and案例3:查詢員工名中第二個字元為_的員工名
select
last_name
from
employees
where
last_name like
'_$_%'
escape
'$';
案例1:查詢員工編號在100到120之間的員工資訊①使用between
and 可以提高語句的簡潔度
②包含臨界值
③兩個臨界值不要調換順序
select
*from
employees
where
employee_id >=
120and employee_id<=
100;
3.inselect
*from
employees
where
employee_id between
120and
100;
案例:查詢員工的工種編號是 it_prog、ad_vp、ad_pres中的乙個員工名和工種編號含義:判斷某字段的值是否屬於in列表中的某一項
特點: ①使用in提高語句簡潔度
②in列表的值型別必須一致或相容
③in列表中不支援萬用字元
select
last_name,
job_id
from
employees
where
job_id =
'it_prot'
or job_id =
'ad_vp'
or job_id =
'ad_pres'
;
4、is nullselect
last_name,
job_id
from
employees
where
job_id in
('it_prot'
,'ad_vp'
,'ad_pres'
);
案例1:查詢沒有獎金的員工名和獎金率=或<>不能用於判斷null值
isnull或is
notnull 可以判斷null值
查詢有獎金的員工名和獎金率select
last_name,
commission_pct
from
employees
where
commission_pct is
null
;
安全等於 <=>select
last_name,
commission_pct
from
employees
where
commission_pct is
notnull
;
查詢沒有獎金的員工名和獎金率
案例2:查詢工資為12000的員工資訊select
last_name,
commission_pct
from
employees
where
commission_pct <=>
null
;
is null pk <=>select
last_name,
salary
from
employees
where
salary <=>
12000
;
is
null:僅僅可以判斷null值,可讀性較高,建議使用
<=> :既可以判斷null值,又可以判斷普通的數值,可讀性較低
MySQL 尚矽谷 筆記3
1.length 獲取引數值的位元組個數 utf 8乙個漢字代表3個位元組,gbk為2個位元組 select length john select length 張三丰hahaha 2.concat 拼接字串 select concat last name,first name 姓名 from em...
MySQL 尚矽谷 筆記5
語法 select 查詢列表 from 表名 where 篩選條件 order by 排序的字段或表示式 特點 1 asc代表的是公升序,可以省略 desc代表的是降序 2 order by子句可以支援 單個字段 別名 表示式 函式 多個字段 3 order by子句在查詢語句的最後面,除了limi...
MySQL 尚矽谷 學習筆記1
使用資料庫 use myemployees 1.查詢表中的單個字段 select last name from employees 2.查詢表中的多個字段 select last name,salary,email from employees 3.查詢表中的所有字段 方式1 select empl...