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