【起別名】
1. AS
SELECT
employees.salary AS 工資
FROM
employees
2. 空格
SELECT
employees.salary 工資
FROM
employees
3. 有空格或者關鍵字的‘out put’ 單引號或者雙引號括起來,
SELECT
employees.salary 'out put'
FROM
employees
【去重 DISTINCT】
# 查詢員工表中涉及到所有的部門編號
SELECT DISTINCT employees.department_id FROM employees`
【不同欄位拼接 CONCAT】
# 把員工的名和姓拼接起來
SELECT CONCAT(employees.first_name,' ', employees.last_name) AS 姓名 FROM employees
【條件查詢 WHERE】
1. 按條件運算式,查找工資>12000的員工
SELECT * FROM employees WHERE salary > 12000;
2. 按邏輯運算式篩選
&& 等價于 and
|| 等價于 or
! 等價于 not
# 篩選工資1w~2w之間的員工
SELECT
employees.last_name,
employees.salary,
employees.commission_pct
FROM
employees
where
salary >= 10000 and salary <= 20000
3. 模糊查詢
3.1 like 和通配符搭配使用
% 任意多個字符
\_任意單個字符
# 篩選員工第二個為_的記錄
SELECT
employees.last_name
FROM
employees
where
last_name like '_\_%'
# 第一個_是通配符表示任意1個字符,第二個_\對_起到了轉義作用
# 表示字符_
3.2 between and
# 篩選工資1w~2w之間的員工
SELECT
*
FROM
employees
where
salary BETWEEN 10000 AND 20000
3.3 in
含義: 判斷某欄位的值是否屬于in串列中的某一項
,只支持精確查找,不支持模糊查找!如IN('AD_%')是錯誤的,因為in相當于=
SELECT
last_name,job_id
FROM
employees
where
job_id IN('IT_PROT','AD_VP','AD_PRES')
3.4 is null / is not null
查詢沒有獎金的員工(嗚嗚嗚好可憐)
注意:=或者 < > 不能用于判斷null值
一定要寫標準 is null
SELECT
last_name,job_id
FROM
employees
where
commission_pct is NULL
between and
in
is null / is not null
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/259799.html
標籤:其他
上一篇:MyBatis10_插件
