MySQL高階查詢(一)

2021-10-06 07:46:13 字數 1125 閱讀 3513

字串連線

select concat(『my』,『sql』,『5.5』) as result;

字串替換

select insert(『abcdef』,3,2,『mysql』);

獲取日期

select now();

select curdate(),curtime();

select week(now());

select year(now()),month(now()),day(now()),hour(now()) as 小時,minute(now());

select datediff(now(),『1995-12-29』);

修改表名

alter table《舊表名》 renane [to] 《新錶名》;

新增字段

alter table 表名 add 欄位名 資料型別 [屬性];

修改字段

alter table 表名 change 原欄位名 新欄位名 資料型別 [屬性];

刪除字段

alter table 表名 drop 欄位名;

– 新增主鍵

alter table test add constraint 主鍵名 primary key (主鍵字段);

– 新增唯一鍵

alter table test add constraint 鍵名 unique(字段);

dml語句

insert into 表名 [(欄位名列表)] values (值列表);

insert into 新錶(欄位名列表)

values(值列表1),(值列表2),……,(值列表n);

更新資料

update 表名

set 欄位1=值1,欄位2=值2,…,欄位n=值n

[where 條件];

刪除資料

delete from 表名 [where 條件];

mysql高階查詢(一)

修改表 修改表名 alter table 舊表名 rename to 新錶名 新增字段 alter table 表名 add 欄位名 資料型別 屬性 修改字段 alter table 表名 change 原欄位名 新欄位名 資料型別 屬性 刪除字段 alter table 表名 drop 欄位名 新...

高階一 Mysql基礎查詢

基礎查詢示例 總結select 查詢列表 from 表名 1.查詢的結果集 是乙個虛擬表 2.select 查詢列表 類似於 system.out.println 列印內容 select 後面跟的查詢列表,可以有多個部分組成,中間用逗號隔開 例如 select 欄位1,欄位2,表示式 from 表名...

mysql高階查詢in MySQL高階查詢(一)

in 子查詢 巢狀查詢 重點是思路 為什麼要用in?in 在數值上相當於 但是它可以查詢到更多的符合條件的結果,等於號只可以查詢乙個結果 question 有兩種方法 第一種 使用子查詢替換表連線 使用 inner join 將表與表之間聯動,再將實現條件依次寫出來 第二種 採用子查詢 在where...