(二)MySQL常見的查詢

2022-09-04 23:45:21 字數 1396 閱讀 5598

條件查詢:

select 查詢列表 from 表名 where 篩選條件;

分類:

一:按條件表示式進行篩選

簡單條件運算子:< > = != <> >= <=

二:按照邏輯表示式進行篩選

邏輯運算子:&& || ! and or not

&& and 表示的是:兩個都為true的時候,結果才為true

|| or 表示的是:其中乙個結果為true的時候,結果就為true

! not 表示的是:取反

三:模糊查詢

like

between

in

is null

is not null

#查詢部門編號不等於90的員工號和部門號

select last_name,department_id from employees where department_id!='90'

select last_name,department_id from employees where department_id<>'90'--推薦使用這種方式

--一共檢索出103條記錄,!=  和  <>的作用想過是相同的

#查詢部門編號不在90-110之間,或者薪水在10000以上的(下面這兩種寫法都是正確的)

select * from employees a where a.department_id<90 or a.department_id>110 or a.salary>100000

select * from employees a where not(a.department_id>=90 and a.department_id<=110 ) or a.salary>100000

#其中_表示的是單個字元的模糊匹配

#查詢員工姓名中第三個字元是a ,第五個字元為e的員工的姓名和工資

select last_name,salary from employees where last_name like '__a_e';

#查詢姓名中第二個字元為_的員工姓名

#其中\表示的是轉義

select last_name from employees where last_name like '_\_%'

#或者 自定義轉移符號

select last_name from employees where last_name like '_$_%' escape '$'

#使用between and 查詢員工編號在100-120之間的員工資訊

select * from employees where employee_id between 100 and 120;

mysql查詢常見操作

concat str1,str2,如果某個str為null,整體為null concat ws separator,str1,str2,不會出現單個欄位null就null的情況 group concat 列名 表示分組之後,根據分組結果,使用group concat 來放置每一組的某字段的值的集合 ...

Mysql 常見查詢命令

查詢mysql的日誌 查詢錯誤日誌檔案路徑 mysql show variables like log error 查詢通用日誌檔案路徑 mysql show variables like general log file 查詢慢查詢日誌檔案路徑 mysql show variables like ...

mysql查詢第二列 MySQL查詢 二

mysql架構 邏輯架構圖 mysql執行流程圖 mysql主要分為server層和儲存引擎層 service層 聯結器 主要負責使用者登入資料庫,進行使用者的身份認證,包括校驗賬戶密碼,許可權等操作 查詢快取 建立連線,執行查詢語句,會先查詢快取,mysql會先校驗這個sql是否執行過,以 的鍵值...