2021年7月6日星期二

MySQL之where条件数据筛选

语法:

-- select * from 表名 where 条件;

测试数据:

-- 建表语句create table `student` (`sid` int(11) primary key auto_increment,`sname` varchar(20) not null,`sex` varchar(10) default null,`isdelete` tinyint(1) default 0)charset=utf8;-- 插入数据insert into `student`(`sid`, `sname`, `sex`) values(0, '达摩', '男'),(0, '典韦', '男'),(0, '曹操', '男'),(0, '钟无艳', '女'),(0, '孙悟空', '男'),(0, '兰陵王', '男'),(0, '程咬金', '男'),(0, '刘备', '男'),(0, '刘禅', '男'),(0, '孙尚香', '女'),(0, '孙膑', '男');

比较运算符

  • 等于: =
  • 大于: >
  • 小于 :<
  • 大于等于: >=
  • 小于等于 :<=
  • 不等于: !=或者<>
-- 查询sid小于3的学生信息select * from student where sid<3;

执行结果:

逻辑运算符

  • 且:and
  • 或: or
  • 非:not
-- 查词 sid 大于 8 并且 sex 为 男 的学生select * from student where sid>8 and sex='男';-- 查询 sid 大于等于 10 或者 sid 小于 3 的学生;select * from student where sid>=10 or sid<3;-- 查询 sid 不大于 3 的学生select * from student where not sid>3;

执行结果:

优先级:not>and>or

注意:and 比 or 优先运算。如果同时出现并希望 or 优先运算,可以使用小括号。

模糊查询----like

  • % 表示匹配一个或多个任意字符

    select * from student where sname like '孙%';select * from student where sname like '%无%';select * from student where sname like '孙%' or sname like '%无%';

执行结果:

  • _ 表示匹配一个任意字符

    select * from student where sname like '孙_';select * from student where sname like '孙__'; -- 两个下划线

范围查询

  • 非连续范围查询:in

    select * from student where sid in(1,2,3,8);

    执行结果:

    注:假如没有第 8 条数据,不会报错,只是没有返回值而已

  • 连续范围查询:between ... and ...

    select * from student where sid between 3 and 8;select * from student where sid between 3 and 8 and sex='男';

    执行结果:

    注 1:假如没有第 8 条数据,不会报错,只是没有返回值而已

    注 2:between…and…和 and 同时运用,会优先计算 between…and…

空与非空

  • 空判断:is null
  • 非空判断:is not null
-- 查询没有性别信息的同学select * from student where sex is null;

执行结果:

注意:null' '的不同。null就是空,在计算机中不占用任何内存;' '为空字符
串,需要占据一定内存。

聚合函数

请查看MySQL之函数一节

分组----group by

敬请期......

原文转载:http://www.shaoqun.com/a/849313.html

跨境电商:https://www.ikjzd.com/

万色:https://www.ikjzd.com/w/2382

心怡科技:https://www.ikjzd.com/w/1327

新单:https://www.ikjzd.com/w/79


语法:--select*from表名where条件;测试数据:--建表语句createtable`student`(`sid`int(11)primarykeyauto_increment,`sname`varchar(20)notnull,`sex`varchar(10)defaultnull,`isdelete`tinyint(1)default0)charset=utf8;--插入数据ins
如何注册全球速卖通?如何管理全球速卖通账户?:https://www.ikjzd.com/articles/91353
2019下半年亚马逊选品风向标:十大热门品类全年销售趋势:https://www.ikjzd.com/articles/91354
亚马逊大量商户账户面临危险,卖家注意了!:https://www.ikjzd.com/articles/91355
中国不喜欢贸易战,但我们也绝不害怕它:https://www.ikjzd.com/articles/91356
他JJ又粗又长的查插我 姐夫,嗯啊,痛,慢点插:http://lady.shaoqun.com/a/274839.html
我和小姨子偷情的那点事(5/5):http://lady.shaoqun.com/a/64813.html
狗狗 紫黑的粗硕用力挺入撕 口述被大公狗塞的满满的:http://lady.shaoqun.com/m/a/246905.html
趴着把腿张开给男友进 我张开双腿疯狂迎合他:http://www.30bags.com/m/a/249741.html
2021年深圳宝博会在哪里、怎么去:http://www.30bags.com/a/474675.html
深圳世界之窗啤酒节门票价格2021:http://www.30bags.com/a/474676.html
2021深圳宝博会展区介绍:http://www.30bags.com/a/474677.html
2021深圳宝博会时间什么时候:http://www.30bags.com/a/474678.html

没有评论:

发表评论