- 9.1 聚集函数
- AVG()平均值
- COUNT()返回某列行数
- MAX()返回某列最大值
- MIN()返回某列最小值
- SUM返回某列值之和
- 9.1.1 AVG( )函数
- SELECT AVG(prod_price) AS avg_price
- FROM products;
- 9.1.2 COUNT( )函数
- SELECT COUNT(cust_email) AS num_cust
- FROM Customers;
- 9.1.3 MAX( )函数
- SELECT MAX(prod_price) AS max_price
- FROM Products;
- 9.1.4 MIN( )函数
- SELECT MIN(prod_price) AS min_price
- FROM products;
- 9.1.5 SUM( )函数
- /*SELECT SUM(quantity) AS items_ordered
- FROM orderitems
- WHERE order_num = 20005;*/
- ---------------------------------------
- SELECT SUM(item_price*quantity) AS total_price
- FROM orderitems
- WHERE order_num = 20005;
- 9.2 聚集不同值
- SELECT AVG(DISTINCT prod_price) AS avg_price
- FROM products
- WHERE vend_id = 'DLL01';
- 9.3 组合聚集函数
- SELECT COUNT(*) AS num_items,
- MIN(prod_price) AS price_min,
- MAX(prod_price) AS price_max,
- AVG(prod_price) AS price_avg
- FROM products;
- 9.4 小结