mysql模糊查询语句_Mysql查询语句练习

一. 练习用表展示

Student

c826c0aebd69e9abe0c87bcbfafbc1c8.png

Course

b9653b0cf66b0d6778c58abaa375fbb7.png

Score

9a9d8910fc0dcc6fd9f25e3dfb445a3c.png

teacher

904d3b44c46f177a8c9b14eedb16f76e.png

二.练习

1.select查询

展示查询语句及结果

-- 查询学生表

ec862e9743145bb09f446663b2f40c68.png
-- 查询学生表所有信息
select * 
from student;

772cb07dce27d2b5345d34e7aac01af8.png
-- 查询姓名,性别并自定义别名(as的用法)
select 姓名 as s_name,性别 as '人类性别'
from student;

467787d4222a2be69b8e8a9fec437144.png
-- 查找不重复姓名(distinct用法)
select  DISTINCT 姓名
from student;

baca063d481072af78622e18e4fab23a.png
-- 查找多列不重复(姓名 学号)
select DISTINCT 学号,姓名
from student;

dbe2531bdf8305fb01137ce5ff51f62c.png

2.算术运算符查询练习

展示查询语句及结果

-- 使用运算符查询
-- 求成绩百分比
SELECT 学号,成绩,成绩/100 as '百分比成绩'
from score;

f1625cde5fddddad01627495ca65635d.png
-- 比较运算符号(=)
SELECT 姓名,学号
from student
where 姓名='猴子';

ec3b3e08e9e5deedc8be596cce92ce16.png

90b9e76bcdc8d4fc56deec9072e50903.png

6b2e950187488df5e0642a9ba7c3a90e.png
-- 查询NULL值
select 教师号,教师姓名
from teacher
where 教师姓名 is NULL;

12c193aaedda059d40767b2e08819cd3.png
-- 查询非null值
select 教师号,教师姓名
from teacher
where 教师姓名 is not NULL;

4bb564b6198f5e2d728d013f56b710fe.png

3.逻辑运算符查询练习

展示查询语句及结果

-- 逻辑运算符not
SELECT 学号,成绩
FROM score
where not 成绩>=60;-- 成绩小于60

6e244d7bdc0899414fbd126553959b67.png
-- 逻辑运算符and
select 学号,成绩
from score
where 成绩>=60 and 成绩<=90; -- 成绩 between 60 and 90;

24969ab74095beb561db5216e047e36e.png
-- 逻辑运算符or
select 姓名,性别
from student
where 性别='男' 
and (姓名='马云'or 姓名= '猴子');-- 性别男,姓名为马云或者猴子

855b4998bfae3a25ed7b0e0ec40bfe1e.png
-- 范围查询between
select 学号,成绩
from score
where 成绩 between 60 and 90;

66799f4ca26536a7997f2b29a8ea8d3a.png
select 学号,成绩
from score
where 成绩 <60 OR 成绩 >90;-- 小于60,大于90的成绩都会被选

f8c0c8d3d6b2eddb68edbefae038b66f.png
-- in 的用法
select 姓名,性别
from student
where 性别='男'
 and 姓名 in ('马云', '猴子');

457245d453628504b7cb5a89fa15a117.png
-- not in
select 姓名,性别
from student
where 性别='男'
 and 姓名 not in ('马云', '猴子');

3727c469bf6ab7a28b73d0d4025db6f6.png

4.模糊查询练习

展示查询语句及结果

-- 查找姓猴的学生名单
select *
from student
where 姓名 like '猴%';

6cea9d0af76189d0a70f92c33e95128c.png
-- 查找名字最后一个字是猴的学生名单
select *
from student
where 姓名 like '%猴';

9442c20123d02d6104c767553b9aff2f.png
-- 查找姓名中带猴的名字的学生名单
SELECT*
FROM student
WHERE 姓名 like'%猴%';

4d5a392ef0b35588442ad50830a88ed5.png
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值