집 >데이터 베이스 >MySQL 튜토리얼 >MySQL数据汇总与聚集函数――MySQL系列(七)_MySQL
聚集函数是运行在行组上,计算和返回单个值的函数。
SELECT AVG(prd_price) AS avg_price FROM productsWhere vend_id=1003;将过滤出vend_id=1003的产品,avg是这些产品的平均值.
SELECT SUM(num) AS prod_sum---返回指定订单号中的商品数量FROM productsWhere order_id=123456;SUM()也可以合计计算值。
SELECT SUM(item_price*num) AS totol_price FROM order_items--返回订单中所有商品价格和。Where order_id=123456;
SELECT AVG(DISTINCT prd_price) AS avg_price FROM productsWhere vend_id=1003;
SELECT count(*) AS num, MIN(prod_price) AS price_min, MAX(prod_price) AS price_max, AVG(prod_price) AS price_avgFROM products;