MySQL 3 資料庫的查詢和幾個函式

2021-08-30 13:40:59 字數 1251 閱讀 3340

對於包含文字的查詢,可以使用like,下面舉例說明:

有一張手機內容**的資料如下:

1)我們想要查詢到諾基亞開頭的資料,可以用like+%模糊查詢,語句如下:

select goods_id,goods_name from goods where goods_name like '諾基亞%';
而後面的%是模糊查詢,則無論多少字元都查詢出來。

結果如下:

2)而有時我們需要精確查詢,比如諾基亞後面有三個字元的,這時候可以用「_」,乙個下劃線表示乙個字元。

舉例如下:

select goods_id,goods_name from goods where goods_name like '諾基亞___';
結果如下:

2.一些函式:

1)substring(a,n);表示去掉a字元的前n-1個字元。

2)concat(a,b,c,…);表示將括號裡的字元給合併起來。

比如我們要將諾基亞開頭的所有名稱改為htc開頭。

我們首先將諾基亞去掉

substring(goods_name,4);
再把htc合併。

concat('htc',substring(goods_name,4));
完整語句:

select goods_id,concat('htc',substring(goods_name,4)) from goods 

where goods_name like '諾基亞%';

結果如下:

就當做筆記~

資料庫那點事 Mysql 3

語句賞析 create table group id int primary key auto increment,name varchar 10 not null,max size int default 10 type varchar 10 not null check type in 研發組 ...

MySQL3 資料庫的操作語句

1.建立資料庫 create database 資料庫名 資料庫系統預設使用utf 8字符集 可以使用中文 0.檢視系統所支援的字符集 show charset 1.檢視系統支援的字符集校驗規則 show collation 2.檢視系統預設字符集以及字元校驗規則 show variable lik...

mysql 3資料庫 資料表 sql檔案

資料庫 資料表 刪除表字段 alter table 表名 drop 表頭 注 如果資料表中只剩餘乙個欄位則無法使用drop來刪除字段。刪除列 alter table 表名 drop column 表頭 刪除改表頭對應的列 查詢資料 select 表頭 from 資料表 重新命名資料表renameta...