文档介绍:12·汇总函数
'tomers;nt(*) as num_custe
函数
说明
AVG()
返回某列的平均值
MAX()
返回某列的最大值
COUNT()
返回某列的行数
SUM()
返回某列值之和
MIN()
返回某列的最小值
select avg(prod_price) as avg_price from products;
+-----------+
| avg_price |
+-----------+
| |
+-----------+
select avg(prod_price) as avg_price from products where vend_id = 1003;
+-----------+
| avg_price |
+-----------+
| |
+-----------+
COUNT(*)对表中行的数目进行计数,不管列中包含的是NULL值还是非NULL值。
COUNT(column)对特定列中具有值的行进行计数,忽略NULL值。
select count(*) as num_cust from customers;
+----------+
| num_cust |
+----------+
| 5 |
+----------+
select
vend_name, prod_name, prod_price
from
vendors,
products
where
=
order by vend_name , prod_name;
select
vend_name, prod_name, prod_price
from
vendors,
products
order by vend_name , prod_name;
select
vend_name, prod_name, prod_price
from
vendors
inner join
products ON = ;
select
prod_name, vend_name, prod_price, quantity
from
orderitems,
products,
vendors
where
=
and =
and order_num = 20005;
select
cust_name, cust_contact
from
customers
where
cust_id in (select
cust_id
from
orders
where
ord