[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; 

 



posted @   Jelly_lyj  阅读(413)  评论(0编辑  收藏  举报
编辑推荐:
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
阅读排行:
· [翻译] 为什么 Tracebit 用 C# 开发
· Deepseek官网太卡,教你白嫖阿里云的Deepseek-R1满血版
· DeepSeek崛起:程序员“饭碗”被抢,还是职业进化新起点?
· 2分钟学会 DeepSeek API,竟然比官方更好用!
· .NET 使用 DeepSeek R1 开发智能 AI 客户端
点击右上角即可分享
微信分享提示