MySQL中的比较条件、其他比较条件
比较条件:
符号!=也能够表示不等于条件;
示例一:查询employees表中员工薪水大于等于3000的员工的姓名与薪水。
select last_name,salary from employees where salary>=3000;
示例二:查询employees表中员工薪水不等于5000的员工的姓名与薪水。
select last_name,salary from employees where salary <>5000;
其他比较条件:
使用between条件:
可以用between范围条件显示基于一个值范围的行。指定的范围包含一个下限和一个上限;
示例:查询employees表,薪水在3000-8000之间的雇员ID、名字与薪水;
select employee_id,last_name,salary from employees where salary between 3000 and 8000;
使用in条件:
示例:查询employees表,找出薪水是5000,6000,8000的雇员id,名字与薪水;
select employee_id,last_name,salary from employees where salary in (5000,6000,8000);
使用like条件:
示例:查询employees表中雇员名字第二个字母是e的雇员名字;
select last_name from employees where last_name like '_e%';
使用null条件:
null条件,包括is null条件和is not null条件;
is null条件用于控制测试。空值的意思是难以获得的、未指定的、未知的或者不适用的。因此,不能用=,因为null不能等于或者不等于任何值;
示例一:找出employees表中那些没有佣金的雇员ID、名字与佣金;
select employee_id,last_name,commission_pct from employees where commission_pct is null;
示例二:找出employees表中那些有佣金的雇员ID、名字与佣金;
select employee_id,last_name,commission_pct from employees where commission_pct is not null;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix