分組函式
查詢交叉連線
子查詢聯合查詢
插入刪除
檢視變數
儲存過程和函式
流程控制結構
字元函式
length
concat
upper/lower
substr/substring
instr
trim
lpad/rpad
replace
數學函式
round
ceil
floor
truncate
mod
日期函式
now
curdate
curtime
year/month/day/hour/minute/second
str_to_date
date_format
datediff
其他函式
流程控制函式# 獲取版本號
select version() # 結果為:8.0.19
# 檢視當前使用的資料庫
select database() # 結果為:dbtest
# 檢視當前的使用者
select user() # 結果為:root@localhost
if
case# 與三目運算子類似
select if(10>5,'big','small') # 結果為:big
/* id為偶數就是厲害的公司,id為奇數就是不厲害的公司 */
select
case id%2
when 0 then name end as 厲害的公司,
case id%2
when 1 then name end as 不厲害的公司
from dep;
使用二
# 查詢年齡大於20的名字,如果不是則為無
select case
when age>20 then name
else '無'
end as 姓名
from euser;
內連線
外連線左/右外連線
全外連線
交叉連線多行操作符
in/not in
any/some
all
exists關鍵字
select exists(查詢語句)
# 返回結果為1/0
delete可以加where條件,truncate不能
truncate刪除整表的效率比delete高
使用delete刪除資料後,自增序列從斷點開始;truncate從1開始
truncate刪除無返回值,delete有
truncate刪除不能回滾,delete能
使用者變數
區域性變數
MySQL學習筆記 2 MySQL高階
mysql學習筆記 2 mysql高階 1.mysql資料庫邏輯結構 innodb儲存的邏輯結構包括 表空間 table space 段 segment 區 extent 塊 頁 block page 預設情況下,所有資料都儲存在共享表空間中。如果設定了innodb file per table,每...
MySQL學習筆記 高階聯結(重要)
select p.name as p name,c.name as c name,b.name as b name,price1,model from product as p,product category as c,brand as b where p.categoryid c.id and ...
MySql 高階 查詢擷取分析 學習筆記
尚矽谷 mysql 高階思維導圖 思維導圖 mmap html格式 在實際的應用中 面對實際的專案系統時,不需要對所有的 sql 都建立索引,費時費力。只需要統計出系統中,使用頻率最高的 查詢時間最慢的 一些 sql 語句即可,也就是 八二原則 處理 20 的 sql,達到 80 的優化。統計出 這...