第12章 汇总数据
1.聚类函数
| 函数 | 描述 |
|---|
| avg() | 返回某列的平均值 |
| count() | 返回某列的行数 |
| max() | 返回某列的最大值 |
| min() | 返回某列的最小值 |
| sum() | 返回某列值之和 |
select avg(prod_price) as avg_price from products;
select avg(prod_price) as avg_price from products where vend_id = 1003;
select avg(item_price) as avg_itemprice,avg(quantity) as avg_quantity from orderitems;
select count(*) as num_cust from customers;
select count(cust_email) as num_cust from customers;
select max(prod_price) as max_price from products;
select max(prod_name) from products;
select min(prod_price) as min_price from products;
select min(prod_name) from products;
select sum(quantity) as items_ordered from orderitems;
select sum(quantity) as items_ordered from orderitems where order_num = 20005;
select sum(quantity * item_price) as total_price from orderitems where order_num = 20005;
select avg(distinct prod_price) as avg_price from products where vend_id = 1003;
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;