Loading

MYSQL.条件查询

语法

SELECT 字段名 FROM 表名 WHERE 查询条件;

条件表达式

>

SELECT * FROM boys WHERE id > 2;

<

SELECT * FROM boys WHERE id < 3;

=

SELECT * FROM boys WHERE id =3;

<>(!=)

SELECT * FROM boys WHERE id <> 3;

>=

SELECT * FROM boys WHERE id >= 2;

<=

SELECT * FROM boys WHERE id <= 3;

逻辑表达式

AND(&&)

两个条件都为true,结果为true,反之为false

#查询张无忌的信息
SELECT * FROM boys WHERE id <= 3 AND userCp = 100;

OR(&&)

只要有一个条件为true,结果为true,反之为false

#查询张无忌的信息
SELECT * FROM boys WHERE id = 1 OR userCP = null;

NOT(!)

如果连接的条件本身为false,结果为true,反之为false

#查询不是张无忌的信息
SELECT * FROM boys WHERE  NOT id = 1;

模糊查询

LIKE

用于查询某段中包含某个字符,一般和通配符搭配使用

#查询不是张无忌的信息
SELECT * FROM boys WHERE boyNAME LIKE '%无忌'; 

BETWEEN AND

用于查询a到b值之间的信息

#查询id号1到4的boys的信息
SELECT * FROM boys WHERE boyNAME BETWEEN 1 AND 4;

IN

用于判断某字段的值是否属于in列表中的某一项

#查询id号为1或者2或者3的boys的信息
SELECT * FROM boys WHERE boyNAME IN (1,2,3);

IS NULL(<=>)

用于判断是否为null值

#查询boyNAME值为null的信息
SELECT * FROM boys WHERE boyNAME IS NULL;
SLECT * FROM boys WHERE boyNAME <=> null;
posted @ 2020-11-17 14:55  yonugleesin  阅读(147)  评论(0编辑  收藏  举报