MySql 条件查询1

 

 

 

 

 

#三.条件查询

条件查询:是用户按照一定条件查询,查询满足条件的部分记录

语法:select 查询内容 from 表 where 条件

1.比较运算符的使用

 = >< >= <= != <>

例如:查询部门号为20的雇员信息

select * from emp where deptno =20

例如:查询薪资大于等于3000的雇员信息

select * from emp where sal>=3000

例如:查询薪资小于等于3000的雇员名称,薪资,职位按照薪资升序排序

select ename,sal,job from emp where sal<=3000 order by sal asc

例如:查询雇员的姓名为smith的雇员信息

select * from emp where ename ='smith'

或者

select * from emp where ename ='SMITH'

注意:mysql默认的是不区分大小写,如果需要区分大小写,

 则可以使用binary关键字

例如:查询雇员的姓名为smith的雇员信息

select * from emp where binary ename ='smith'

select * from emp where binary ename ='Smith'

2.[not]between and  的使用可以查询某区间范围的记录

例如:查询薪资在1200-3000之间的雇员信息

select * from emp where sal between 1200 and 3000

例如:查询薪资不在1200-3000之间的雇员姓名,薪资

select ename,sal from emp;

where sal not between 1200 and 3000

order by sal asc

3. [not]in 表示在指定集合中

语法: select 查询内容 from 表名 where 字段名 in(值1,值2....)

列如:查询雇员姓名是smith,scott,king的雇员信息

select * from emp where ename in('smith','scott','king')

列如:查询雇员姓名不是smith,scott,king的雇员信息

select * from emp where ename not in ('smith','scott','king')

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值