2

我有两个表名为:customersbill。客户和账单有一对多的关系。Customer 表包含客户 mobileNo、bikeNo 等的记录 Bill 表包含带有 bikeNo(外键)、billdate 等的客户账单记录。我对此进行了查询:

SELECT        customer.mobileNo, bill.iDate AS Expr1
FROM            (customer INNER JOIN
                     bill ON customer.bikeNo = bill.bikeNo)
ORDER BY bill.iDate;

现在,我如何通过此查询获得不同且最新的账单日期记录和 mobileNo?

4

1 回答 1

3

使用 GROUP BY 和 MAX():

SELECT customer.mobileNo, MAX(bill.iDate) AS iDate
FROM (customer INNER JOIN
                 bill ON customer.bikeNo = bill.bikeNo)
GROUP BY customer.mobileNo
ORDER BY iDate
于 2013-01-01T23:16:27.857 回答