《MySQL必知必会》-第6章 过滤数据

使用select语句的where子句指定搜索条件

  • 使用where子句
select prod_name,prod_price
from products
where prod_price = 2.50;
#检索两个列,返回prod_price值为2.50的行
#where子句在from之后
#若order bywhere同时使用,则order bywhere之后
  • where子句操作符

mysql支持的所有条件操作符

操作符说明
=等于
<>不等于
!=不等于
<小于
<=小于等于
>大于
>=大于等于
between在指定两个值之间
#1 检测单个值
select prod_name,prod_price
from products
where prod_name = 'fuses';
#执行匹配时默认不区分大小写
select prod_name,prod_price
from products
where prod_price < 10;
#2 不匹配检查
select vend_id,prod_name
from products
where vend_id !=(或<>) 1003;
#单引号用来限定字符串,与数值进行比较则不需要引号
#3 范围值检查
select prod_price,prod_name
from products
where prod_price between 5 and 10;
#包括开始值和结束值
#4 空值检查
select prod_name
from products
where prdo_price is null;
#null与字段包含0,空字符串或仅仅包含空格是不同的
select cust_id
from customers
where cust_email is null;
posted @   Mer_curiail  阅读(6)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示