MySql(九)

目录

条件查询

1)准备一张表

2)插入数据

3)条件查询格式

[1---比较运算符 >大于](#1---比较运算符 >大于)

[2---比较运算符 < 小于](#2---比较运算符 < 小于)

[3---比较运算符 >= 大于等于](#3---比较运算符 >= 大于等于)

[4---比较运算符 <= 小于等于](#4---比较运算符 <= 小于等于)

[5---比较运算符 != 不等于](#5---比较运算符 != 不等于)

[6---比较运算符 <> 不等于](#6---比较运算符 <> 不等于)

[7---比较运算符 between ...and .. 某一区间](#7---比较运算符 between ...and .. 某一区间)

[8---比较运算符 in(集合) 某个集合](#8---比较运算符 in(集合) 某个集合)

[9-- 前缀查询](#9-- 前缀查询)

[10-- 后缀查询](#10-- 后缀查询)

[11-- 包括查询](#11-- 包括查询)

逻辑运算符

[1--逻辑运算符 And](#1--逻辑运算符 And)

[2--逻辑运算符 &&](#2--逻辑运算符 &&)

[3--逻辑运算符 ||](#3--逻辑运算符 ||)

[4--逻辑运算符 or](#4--逻辑运算符 or)

[5--逻辑运算符 Not](#5--逻辑运算符 Not)


条件查询

1)准备一张表

sql 复制代码
CREATE table role(
 roleid INT PRIMARY KEY AUTO_INCREMENT,
 rolename VARCHAR(200),
 roleskill VARCHAR(300),
 rolesex CHAR(1),
 rolemonkey int,
 roleinfo VARCHAR(200),
 rolehealth INT
);

2)插入数据

sql 复制代码
INSERT into role VALUES
(null, '小玖', '暗影', '女', 500000, '猎手', 50000),
(null, '暗色', 'coc', '男', 60000, '骑士', 50000),
(null, '黎明', '曙光', '女', 70000, '战士', 50000),
(null, '雪夜', '银色', '男', 30000, '猎人', 50000),
(null, '张久', '酒心', '女', 50000, '肉盾', 50000),
(null, '雪色', '雪风', '男', 50000, '女魔', 50000),
(null, '安久', '蛋定', '女', 50000, '魔法士', 50000);

3)条件查询格式

select 列名 from 表明 where 条件表达式

1---比较运算符 >大于

查找角色金钱大于 70000

select * from role WHERE rolemonkey > 70000 ;

2---比较运算符 < 小于

查找角色金钱小于50000

select * from role WHERE rolemonkey < 50000 ;

3---比较运算符 >= 大于等于

查找角色金钱大于等于60000

select * from role WHERE rolemonkey >= 60000 ;

4---比较运算符 <= 小于等于

查找角色金钱小于等于60000

select * from role WHERE rolemonkey <= 60000 ;

5---比较运算符 != 不等于

查找角色金钱不等于50000

select * from role WHERE rolemonkey != 50000 ;

6---比较运算符 <> 不等于

select * from role WHERE rolemonkey <> 60000 ;

7---比较运算符 between ...and .. 某一区间

查找金钱区间为 50000 到 70000

select * from role WHERE rolemonkey BETWEEN 50000 and 70000;

8---比较运算符 in(集合) 某个集合

查找金钱为30000和60000

SELECT * from role where rolemonkey in(30000,60000);

9-- 前缀查询

select * from role where rolename like '雪%';

10-- 后缀查询

select * from role where roleinfo like '%士';

11-- 包括查询

SELECT * from role where roleinfo LIKE '%法%';

逻辑运算符

1--逻辑运算符 And

SELECT * from role where rolename = '张久' and rolemonkey = 50000;

2--逻辑运算符 &&

SELECT * from role where rolename = '雪色' && rolemonkey = 50000;

3--逻辑运算符 ||

select * from role where roleskill = '银色' || roleskill = 'coc';

4--逻辑运算符 or

select * from role where roleinfo = '猎手' or roleinfo = '女魔';

5--逻辑运算符 Not

select * from role where not(roleinfo = '猎手' or roleinfo = '女魔');

相关推荐
七度黑光3 小时前
用 openclaw 给故障复盘打分:质量审核自动化实践
运维·服务器·前端·数据库·自动化
qq_283720053 小时前
MySQL技巧(九): Binlog 完整格式解析(ROW 模式,默认)
mysql·binlog·数据恢复
华科易迅4 小时前
Spring 事务(注解)
java·数据库·spring
Java面试题总结4 小时前
MySQL篇 索引失效
数据库·mysql
last demo4 小时前
mysql
运维·数据库·mysql·oracle
kevin_cat6 小时前
oracle 扩展表空间
数据库·oracle
花间相见6 小时前
【MySQL面试题】—— MySQL面试高频问题汇总:从原理到实战,覆盖90%考点
数据库·mysql·面试
高梦轩7 小时前
MySQL 数据库备份与恢复
数据库·oracle
一直都在5727 小时前
Redis(二)
数据库·redis·缓存
TDengine (老段)7 小时前
TDengine IDMP 工业数据建模 —— 属性
大数据·数据库·人工智能·时序数据库·tdengine·涛思数据