查询语句like

本文介绍了SQL查询中LIKE操作符的使用方法,包括通配符匹配、范围查询以及不建议使用的IN关键字。同时详细讲解了聚合函数如COUNT、MAX、MIN、AVG和SUM的用法及其在获取特定数据统计方面的应用。
摘要由CSDN通过智能技术生成
#like用法,where 后先写查询列再写like最后匹配字符串
SELECT * FROM student where username like '杨%';
SELECT * FROM student where introduce like  '%大%';
SELECT * FROM student where username like '杨_';
#范围查询  betwween--and 包括==的
SELECT * FROM student where age between 20 and 30 ;
SELECT * FROM student where createdate between '2024-02-21 00:00:00' and '2024-02-25 00:00:00';
#in 关键字的使用不建议使用关键字因为不一定走索引在百万表的数据中会很卡
SELECT * FROM student where username in ('杨过','龙姑娘');

聚合函数

#聚合函数  数量count 最大值max 最小值min 平均值avg 求和sum
SELECT count(*)'所有成年人数量' from student where age>=18;
select max (age)'最大年龄',min(age)'最小年龄'from student;
select avg (age)'平均年龄'from student;
select sum (age)'总年龄'from student;
select avg (age)'avg出的总年龄',sum(age)/(select count(*) from student ) '计算出的'from student;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值