mysql基础——表的增删查改二06

本文介绍 SQL 中的条件查询方法,包括使用 where 关键字进行精确及模糊匹配查询、利用逻辑运算符进行组合条件筛选、以及使用 in 和 between 运算符进行范围查询。此外,还介绍了如何利用聚合函数 sum、avg、count、max 和 min 对查询结果进行统计汇总,并简述了子查询的应用。

条件查询[where  关键字]

select  *  from  product  where  price  >60;

where后可用条件运算符>  >=  <  <=  =  !=  <>不等


select  *  from  product  where  price  >  10  and  price  <100;

select  *  from  product  where  price  between  10  and  100;


逻辑运算  and  ,  or  ,  not

select  *  from  product  where  price  <  100  or  price  >  900;


like:模糊查询

_:代表一个字符

%:代表多个字符

select  *  from  product  where  pname  like  '%饼%'


in  在某个范围中的值

select   *  from  product  where  cno  in(1,4,5);


asc  升序

desc  降序

select  *  from  product  order by price  asc/desc


聚合函数

sum()求和    select  sum(price)  from  product;

avg()求平均值  select  avg(price)  from  product;

count()求数量  select  count(*)  from  product;

max()

min()


子查询

select  *  from  product  where  price  >  (select  avg(price))from  product);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值