8.SQL必知必会第八课 使用聚集函数汇集数据
作者:互联网
一、知识
有时候,我们需要对某列数据做简单处理。(求和,求平均、取最大、取最小等)就需要用到聚集函数。聚集函数有如下5个。
AVG()//取平均
COUNT()//取这一列的行数
MAX()//取这一列的最大值
MIN()//取这一列的最小值
SUM()//取这一列之和
试举一例:
select avg(prod_price)
as avg_price
from tyqsl2.products
再举一例:
SELECT count(*) as numbers_of_items,
avg(prod_price) as avg_price,
max(prod_price) as max_price,
min(prod_price) as min_price
FROM tyqsl2.products;
二、课后习题
SELECT sum(quantity)
FROM tyqsl2.orderitems;
SELECT sum(quantity)
FROM tyqsl2.orderitems
where prod_id = 'BR01'
select max(prod_price)
as special_price
from tyqsl2.products
where prod_price <= 10
标签:avg,必知,price,第八课,tyqsl2,一列,SQL,prod,SELECT 来源: https://blog.csdn.net/GrandPandababy/article/details/112380773