like mysql 相反_Mysql数据库的常用操作
你這么優(yōu)秀,一定只想把“檸檬班”置頂
▲
本文由檸檬班Python10期VIP學(xué)員Boy原創(chuàng)。
本文主要介紹mysql數(shù)據(jù)庫的查詢操作,捎帶腳增刪改操作。
·增 ·
insert?into:
insert into table (字段) values (數(shù)據(jù))(數(shù)據(jù))...
insert into table values (數(shù)據(jù))(數(shù)據(jù))...
insert into table (列名,列名...) select (列名,列名...) from 表
·刪 ·
drop:
◆ drop datebase "數(shù)據(jù)庫名" -- 刪除數(shù)據(jù)庫
◆ drop table “表名” -- 刪除表
delete?from:
◆ delete from table -- 刪除表中數(shù)據(jù)
◆ delete from table where條件 -- 按條件刪除表中數(shù)據(jù)
·改 ·
update:
update “表名” set 字段=value where 條件
· 查 ·
select:
單表查詢:
◆ select * from table where 條件
◆ select id as?c_id?from table where 條件
多表關(guān)聯(lián)查詢:
◆ 內(nèi)聯(lián)查詢
select * from table1,table2... where 關(guān)聯(lián)條件 and 查詢條件
select * from table1 inner join table2 on 關(guān)聯(lián)條件 ... where 查詢條件
◆ 左聯(lián)查詢
select * from table1 left join table2 on 關(guān)聯(lián)條件 ... where 查詢條件
◆ 右聯(lián)查詢
效果與左聯(lián)查詢效果相反
select * from table1 right join table2 on 關(guān)聯(lián)條件 ... where 查詢條件
◆ union查詢
左聯(lián)查詢、右聯(lián)查詢的查詢結(jié)果去重(去掉重復(fù)數(shù)據(jù))后進(jìn)行合并
select * from table1 left join table2 on 關(guān)聯(lián)條件
union (union all 為不去重將結(jié)果全部合并)
select * from table1 right join table2 on 關(guān)聯(lián)條件
◆ 高級查詢
order by—對查詢結(jié)果進(jìn)行排序
select * from table where 條件 order by 字段(需要排序的字段) asc\desc
select * from table order by 列1 asc,列2 desc...?
(根據(jù)多列進(jìn)行排序,若列1數(shù)據(jù)相同,根據(jù)列2進(jìn)行排序)
in—條件在數(shù)據(jù)集\子查詢中
select * from table where 條件字段 in 數(shù)據(jù)集\子查詢
like—根據(jù)條件模糊查詢
select * from table where 條件字段 like '%_值'?(%--任意字符、_--每個下劃線代表一個字符)
group by—根據(jù)某字段進(jìn)行分組查詢
select * from table where 條件 group by having
between and—查詢條件在某個區(qū)間之間
select * from table where 條件字段 between ... and ...
distinct—對查詢結(jié)果進(jìn)行去重
select distinct(去重字段) from table where 條件
limit—分頁
select * from table where 條件 limit m,n
select * from table where 條件 limit n offset m?
(從偏移m個數(shù)據(jù),查詢n條)
◆ 數(shù)據(jù)庫查詢常用函數(shù)
數(shù)值相關(guān)函數(shù):
max()—最大值、min()—最小值
avg()—平均值、sum()—求和
count()?-- 計(jì)數(shù)、median() -- 中位數(shù)
日期相關(guān)函數(shù):
sysdate()—當(dāng)前日期時期
curdate()—當(dāng)前日期
curtime()—當(dāng)前時間
year()—獲取日期的年份
month()—獲取日期的月份
date_add(日期,interval 變更值 單位)—變更日期
字符串相關(guān)函數(shù):
concat()—拼接字符串
length()—獲取字符串長度
substr()—截取字符串
其他?
◆ desc?“table”
列出表的信息(包含表結(jié)構(gòu)、字段、字段類型、主鍵、外鍵等)
◆ use?"datebase"
打開數(shù)據(jù)庫
◆ <>
條件中的不等于
sql執(zhí)行順序
◆ select ... from ... where ... group by ... having ... order by ...
當(dāng)一條sql語句同時存在where、group?by、having、order?by關(guān)鍵字時,執(zhí)行順序:
(1) FROM left_table
(2) ON join_condition
(3) join_type JOIN right_table
(4) WHERE where_condition
(5) GROUP BY group_by_list
(6) HAVING having_condition
(7) SELECT
(8) DISTINCT select_list
(9) ORDER BY order_by_condition
(10) LIMIT limit_number
?
今日福利
需要數(shù)據(jù)庫增刪改查學(xué)習(xí)視頻
可加小米老師微信:
13327316731
暗號:公眾號
總結(jié)
以上是生活随笔為你收集整理的like mysql 相反_Mysql数据库的常用操作的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CreateJobObject exam
- 下一篇: 单列表_正态分布检验(单样本K-S检验)