/*聚合函数*/
/*count()主要用于计算查询结果中的数据条数*/
select count(*) AS 条数 from Customers where City like 'B%'
select count(distinct CustomerID) FROM Orders
select count(CustomerID) FROM Orders
/*MAX(expression) 查询一列中expression的最大值*/
/*MIN(expression) 查询一列中expression的最小值*/
/*AVG(expression) 查询一列中expression的平均值*/
/*SUM(expression) 查询一列中expression的总和*/
select min(UnitPrice) AS 最低价格 from Products
select max(UnitPrice) AS 最高价格 from Products
select AVG(UnitPrice) AS 平均价格 from Products
select AVG(UnitPrice-10) AS 平均价格 from Products
select SUM(UnitPrice*2) AS 总金额 from Products
select min(UnitPrice) AS 最低价格,
max(UnitPrice) AS 最高价格,
avg(UnitPrice) AS 平均价格,
sum(UnitPrice) AS 总金额
from Product
/*为表指定别名,一旦指定了别名,必须全部使用别名*/
/*在FROM字句指明别名*/
select a.CustomerID,a.City,a.Phone,
b.OrderID,b.EmployeeID,b.OrderDate
from Customers a inner join Orders b on a.CustomerID=b.CustomerID