mysql 格式整理 MySQL資料庫基本操作整理

2021-10-18 10:20:36 字數 1898 閱讀 5838

儲存資料    insert into 表名 values(字段值,字段值,...);

指定字段插入  insert into 表名 (欄位名) values (字段值);

查詢資料    select * from 表名 where 條件;

修改資料    update 表名  set 欄位名=字段值,欄位名=字段值,... where 條件;

刪除資料    delete from 表名 where 條件;

查詢到的字段更名    select 原欄位名 新欄位名 from 表名;

查詢去重        select distinct 欄位名 from 表名;

in 查詢某個欄位的值為多個的時候      select * from where 欄位名 in(值1,值2,...);

查詢某個欄位的值不為**的時候      select * from where 欄位名 not in(值1,值2,...);

between查詢在**之間(之內)     select * from where 欄位名 between 值1 and 值2;

查詢不在**之間的(之外)     select * from where 欄位名 not between 值1 and 值2;

模糊查詢:   like

_:代表單個未知字元

%:代表0個或者多個未知字元

公升序   select * from 表名 order by 字段 asc;

降序   select * from 表名 order by 字段 desc;

分組   select 字段 from 表名 group by 字段;

分頁查詢     select * from 表名 limit (頁數-1)*每頁數量,每頁數量             -----limit 7,7

取餘      mod(7,2)      -----7%2

獲取當前日期+時間      select now();

獲取當前日期      select curdate();

獲取當前時間      select curtime();

從年月日時分秒中提取日期    select date(now());

從年月日時分秒中提取時間    select time(now());

從年與日時分秒中提取時間分量:

年      select extract(year from now());      ------select extract(year from 字段) from 表名;

月      select extract(month from now());

日      select extract(day from now());

時      select extract(hour from now());

分      select extract(minute from now());

秒      select extract(second from now());

日期格式化:

%y 四位年 yyyy

%y 兩位年 yy

%m 兩位月

%c 一位月

%d 日

%h 24小時

%h 12小時

%i 分

%s 秒

-------select date_format(now(),'%y年%m月%d日 %h時%i分%s秒');

非標準格式轉換為標準格式

str_to_date('非標準格式的時間',格式);      --------select str_to_date('2023年11月16日 15時49分08秒','%y年%m月%d日 %h時%i分%s秒');

ifnull(x,y)     ----update emp set comm = ifnull(comm,0);

mysql 整理索引 Mysql索引整理

1 mysql基本單位是頁,大小為16kb 16384 1024 頁是為了增加查詢效率,減少io的互動 區域性性原理 2 頁與頁之間是雙向鍊錶,插入的時候會根據主鍵id進行排序 單葉資料結構.jpg 3 在頁上有乙個頁目錄,相當於把資料進行分組,存放的是當前組最小的主鍵id,指標並且指向對應的資料 ...

mysql語句整理 mysql語句整理

建立資料庫 create database if not exists mybatis 使用某個資料庫 use mysql 刪除資料庫 drop database if exists mybatis create table if not exists 分頁查詢語句 統計總數 select coun...

mysql行格式 MySQL 行格式

以 mysql 預設的儲存引擎 innodb 為例 innodb 包含以下四種行格式 compact redundant dynamic compressed 指定行格式 create table 表名 列的資訊 row format 行格式名稱 alter table 表名 row format ...