请帮帮我... 基于Northwind数据库http://www.pilpoils.be/demos/northwind-db/assets/12f53c79/northwind.gif, 我想编写一个MYSQL查询,显示:每个客户的第一个订单。 我试过但我有困难......这是我的疑问:
select top 1 * from orders inner join customers on orders.customerid=customers.customerid
thnx to all
答案 0 :(得分:0)
SELECT * from Customers AS c
INNER JOIN `Orders` AS o ON c.CustomerID = o.CustomerID
INNER JOIN
( SELECT CustomerID, min(OrderDate) AS mod FROM `Orders` GROUP BY CustomerID ) AS mTable
ON mTable.mod = OrderDate AND mTable.CustomerID = C.CustomerID;