[Mysql 查询语句]——查询指定记录
#比较
等于
select * from orders where order_num = 2006; 大于
select * from orders where order_num > 2006; 小于
select * from orders where cust_id < 10003; 小于或等于
select * from orders where cust_id <= 10003; 大于或等于
select * from orders where cust_id >= 10003; 不等于
select * from orders where cust_id != 10003; 排除掉
select * from orders where cust_id <> 10003;
#指定范围查询 BETWEEN IN
select cust_id from orders where cust_id between 10004 and 10005; select cust_id from orders where cust_id not between 10004 and 10005;
#指定集合查询 IN
select cust_id from orders where cust_id in (10003,10004); select cust_id from orders where cust_id not in(10003,10004);
集合元素可以是字符串类型 select * from student where name in ('taeyeon','jessica');
#匹配字符查询 LIKE
like中可以使用通配符(%)和(_) %表示匹配0个或多个字符 _表示匹配1个字符 select * from employee where name like "Jelly"; select * from employee where name not like "Jelly"; select * from employee where name like "J%y"; select * from employee where name like "K_y"; select * from employee where homeaddr like "北京%";
#查询空值
select * from vendors where vend_state is null; select * from vendors where vend_state is not null;
#带AND|OR的多条件查询
select * from employee WHERE age=26 AND sex like '男'; select * from employee WHERE age=26 OR sex like '男'; select * from employee WHERE id<1005 AND age<26 AND sex='男'; select * from employee WHERE id IN (1001,1005) AND age BETWEEN 20 and 26;
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· [翻译] 为什么 Tracebit 用 C# 开发
· Deepseek官网太卡,教你白嫖阿里云的Deepseek-R1满血版
· DeepSeek崛起:程序员“饭碗”被抢,还是职业进化新起点?
· 2分钟学会 DeepSeek API,竟然比官方更好用!
· .NET 使用 DeepSeek R1 开发智能 AI 客户端