日期:2014-05-17 浏览次数:20423 次
SELECT Shippers.ShipperName, Employees.LastName,
COUNT(Orders.OrderID) AS NumberOfOrders
FROM ((Orders
INNER JOIN Shippers
ON Orders.ShipperID=Shippers.ShipperID)
INNER JOIN Employees
ON Orders.EmployeeID=Employees.EmployeeID)
GROUP BY ShipperName,LastName;
--#1.on->join->group->select
--SQL逻辑执行顺序
(8) SELECT (9) DISTINCT (11) <TOP_specification> <select_list>
(1) FROM <left_table>
(3) <join_type> JOIN <right_table>
(2) ON <join_condition>
(4) WHERE <where_condition>
(5) GROUP BY <group_by_list>
(6) WITH {CUBE
------解决方案--------------------
ROLLUP}
(7) HAVING <having_condition>
(10)ORDER BY <order_by_list>
--#2.当成&&来处理
--ShipperName和LastName,两个字段的组合值一模一样,才会被放到一个组里面。