有时候我们经常需要汇总数据,而不是把他们实际检索出来。 比如:
Paste_Image.png
select avg(prod_price) as avg_price
from products
where vend_id = 'DLL01';
select vend_id, count(*) as num_prods
from products
增加一个distinct参数就可以啦
select avg(distinct prod_price) as avg_price
from products
where vend_id = 'DLL01';