mysql 笔记二

本文介绍了SQL语言中常用的查询技巧,包括使用不同的比较运算符进行筛选、如何利用逻辑操作符AND与OR组合复杂条件、使用IN与NOT IN来匹配特定集合、以及如何正确处理NULL值等。这些技巧对于提升SQL查询效率至关重要。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//查询varchar刑
select * from user where name='gaogao';
//价格小于100元
select * from products where price<100;
//价格小于等于100元
select * from products where price<=100;
//查询姓名不是gaogao的
select * from user where name<>'gaogao'
//查询id 不是10的用户
select * from user where id<>10;
//用另一个 !=
select * from user where id!=10;
//用between 限定范围
select * from user where id between10 and 20;
前一个是开始值,后一个是结束值
如果将20 和10替换掉,就得不到结果
//空值检查
null
select * from user where phone is null;
//逻辑操作符 and
select * from products where id<100 and price<50;
查询出前100个价格低于50元的商品
//or
select * from user where id=10 or id=11;
//or与 and  系统会默认调用and
select * from product where (id>100 or id<10) and price =50
//是查询id大于100或者小于10的商品中,价格为50的商品
如果不加()
select * from product where id>100 or id<10 and price=50
解释为 id小于10并且价格为50的商品,获取id大于100的商品
//in在。。。里
select * from user where id in(10.20.30.40);
//not in 不在。。里,,找出与条件不匹配的行
select * from user where id not in (10.20.30);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值