MySql学习笔记(三) —— 聚集函数的使用
2024-08-30 21:19:10
1.AVG() 求平均数
select avg(prod_price) as avg_price from products; --返回商品价格的平均值 select avg(prod_price) as avg_price from products where vend_id = 1003; --返回生产商id为1003的商品价格平均值
2.COUNT():确定表中行的数目或者符合特定条件的行的数目
select count(*) as num_cust from customers; --统计customers表中的顾客数
select count(email) as num_cust from customers; --统计具有邮件的用户数目
3.max():返回指定列中的最大值
select max(prod_price) as max_price from products; --返回价格最大值
它能够返回任意列的最大值,如果是文本数据时,会返回最后一行。
4.min():返回指定列的最小值
select min(prod_price) as max_price from products; --返回价格最小值
它能够返回任意列的最小值,如果是文本数据时,会返回最前面的行。
5.sum():返回指定列值的和
select sum(quantity) as items_ordered from orderitems where order_num = 20005; --返回订单编号为20005所订购的商品总数
select sum(item*quantity) as total_price from orderitems where order_num = 20005; --返回订单编号为20005所订购的商品总额
最新文章
- aspose words 介绍
- Canvas旋转元素
- Ora-01536:超出了表空间users的空间限量(转)
- 安卓第十四天笔记-内容提供者(ContentProvider)
- AppCache 离线存储 应用程序缓存 API 及注意事项
- php中curl和fsockopen发送远程数据的应用
- shell编程之echo命令
- c++11之智能指针
- 最新模仿ios版微信应用源码
- [Hibernate] List 映射例子
- Django - - - -视图层之视图函数(views)
- win10自带的防火墙Windows Defender
- C#.NET 大型通用信息化系统集成快速开发平台 4.1 版本 - 发送通知功能改进改进
- HTML5基础标签
- MongoDB 之 你得知道MongoDB是个什么鬼 MongoDB - 1
- TCP窗口扩大选项
- 【1】JVM-内存模型
- Java多线程安全问题
- ECLIPSE修改xml配置文件TOMCAT不生效的解决
- html中如何移除video下载按钮