create
table student(
id char(36
)primary
key,
name varchar(8
)not
null
, age int(3
)default0,
mobile char(11
),address varchar
(150))
insert
into student
values
('9b4435ec-372c-456a-b287-e3c5aa23dff4'
,'張三',24
,'12345678901'
,'北京海淀');
insert
into student
values
('a273ea66-0a42-48d2-a17b-388a2feea244'
,'李%四',10
,'98765432130'
,null);
insert
into student
values
('eb0a220a-60ae-47b6-9e6d-a901da9fe355'
,'張李三',11
,'18338945560'
,'安徽六安');
insert
into student
values
('6ab71673-9502-44ba-8db0-7f625f17a67d'
,'王_五',28
,'98765432130'
,'北京朝陽區');
insert
into student
values
('0055d61c-eb51-4696-b2da-506e81c3f566'
,'王_五%%',11
,'13856901237'
,'吉林省長春市寬平區'
);
like:進行資料模糊查詢
1、%:匹配0次或多次
select
*from student where name like
'張三%'
;select
*from student where name like
'李%四'
;
2、_:只匹配1次
select
*from student where name like
'張_'
;
3、escape:取消%或_字元的萬用字元特性
注:escape後面單引號中只能是單個字元;
escape後面可以是字母、#、$、,、\等字元;
select
*from student where name like
'%a%%'
escape
'a';
select
*from student where name like
'%a_%'
escape
'a';
select
*from student where name like
'_a%_'
escape
'a';
select
*from student where name like
'_a__'
escape
'a';
4、邏輯條件:and、or
#查詢張姓且位址中含有北京的學生資訊
select
*from student where name like
'張%'
and address like
'%北京%'
;#查詢張姓或位址中含有北京的學生資訊
select
*from student where name like
'張%'
or address like
'%北京%'
;
5、between 下限 and 上限:等同於「(column_name>=下限) and (column_name<=上限)」
注:「between 下限 and 上限」一定是小值在前大值在後,否則查不出資料;
「between 下限 and 上限」查詢資料報括邊界值;
#查詢年齡在10~28之間的學生資訊
select
*from student where age between
10and28;
#上面sql語句等效於該sql語句
select
*from student where age >=
10and age<=
28;
6、關係條件:=、!=、<、=<、>、>=等
select
*from student where age<28;
--查詢年齡小於28歲的學生資訊
7、in(value1,value2,value3…valuen):等同於「 column_name = value1 or column_name = value2 or column_name = value3… or column_name = valuen 」
select
*from student where age in(11
,24);
8、null :包括is null 和 is not null
select
*from student where address is
null
;select
*from student where address is
notnull
;
MySql模糊查詢總結
在mysql中如何使用模糊查詢呢?在where子句中,可以對datetime char varchar欄位型別的列用like子句配合萬用字元選取那些 很像.的資料記錄,以下是可使用的萬用字元 零或者多個字元 單一任何字元 下劃線 特殊字元 在某一範圍內的字元,如 0 9 或者 aeth 不在某範圍內...
總結MySQL模糊查詢
首先建立表 create table student id char 36 primary key,name varchar 8 not null age int 3 default0,mobile char 11 address varchar 150 insert into student va...
總結MySQL模糊查詢
create table student id char 36 primary key,name varchar 8 not null,age int 3 default 0,mobile char 11 address varchar 150 insert into student values ...