MySQL基本查詢操作

2021-10-10 09:42:54 字數 1824 閱讀 1121

#查詢員工表中涉及到的所有的部門編號(去重)

select

distinct department_id from employees;

#查詢員工姓和名連線成乙個字段,並顯示為姓名

select

concat(last_name, first_name)

as 姓名

from

employees;

#查詢多個值,乙個為0,則全部為null,利用ifnull函式來避免

select

ifnull(commission_pct,0)

as 獎金率

from

employees;

/*

語法:select

查詢列表

from

表名where

篩選條件; (ture or false)

*/#查詢工資》12000的員工資訊

select

*from

employees

where

salary >

12000

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

select

last_name,

department_id

from

employees

where

department_id <>90;

#查詢部門編號不是在90到110之間,或者工資高於15000的員工資訊

select

*from

employees

where

not(department_id >=

90and department_id <=

110)

or salary >

15000

;

#查詢員工名中包含字元a的員工資訊

select

*from

employees

where

last_name like

'%a%'

;#查詢員工名中第三個字元為n,第五個字元為l的員工名和工資

select

*from

employees

where

last_name like

'__n_l%'

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

select

last_name

from

employees

where

last_name like

'_\_%'

;/*

這裡的\是轉義字元

或者 last_name like '_$_%' escape'$';

*/#查詢員工編號在100到120之間的員工資訊

select

*from

employees

where

employee_id between

100and

120;

/* 包含臨界值,且必須左邊小,右邊大 */

#查詢員工的工種編號是it_prot、ad_vp、ad_pres中的乙個員工名和工種編號

select

last_name,

job_id

from

employees

where

job_id in

('it_prot'

,'ad_vp'

,'ad_pres'

);

mysql 查詢日誌基本操作

mysql查詢日誌記錄了所有mysql資料庫請求資訊,由於mysql慢查詢也可以直觀的查詢到資料庫執行資訊,故mysql查詢日誌用到的場景不多。基本操作 1.開啟查詢日誌 set global general log on 2.關閉查詢日誌 set global general log off 3....

mysql基本操作 MySQL基本操作

mysql中新增使用者,新建資料庫,使用者授權,刪除使用者,修改密碼 注意每行後邊都跟個 表示乙個命令語句結束 1.新建使用者 1.1 登入mysql mysql u root p 密碼 1.2 建立使用者 mysql insert into mysql.user host,user,passwor...

mysql 基本操作 mysql基本操作

mysql 建立表,並設定主鍵自增 create table log logid int 4 primary key not null auto increment,logtitle varchar 32 not null logcontent varchar 160 not null logtim...