日期:2014-05-16 浏览次数:20851 次
聚集函数是运行在行组上,计算和返回单个值的函数。
函数 | 说明 |
---|---|
AVG() | 返回某列的平均值 |
COUNT() | 返回某列的行数 |
MAX() | 返回某列的最大值 |
MIN() | 返回某列的最小值 |
SUM() | 返回某个列之和 |
SELECT AVG(prd_price) AS avg_price FROM products Where vend_id=1003;
SELECT SUM(num) AS prod_sum---返回指定订单号中的商品数量 FROM products Where order_id=123456;
SELECT SUM(item_price*num) AS totol_price FROM order_items--返回订单中所有商品价格和。 Where order_id=123456;
SELECT AVG(DISTINCT prd_price) AS avg_price FROM products Where vend_id=1003;
SELECT count(*) AS num, MIN(prod_price) AS price_min, MAX(prod_price) AS price_max, AVG(prod_price) AS price_avg FROM products;