我有两个名为:客户和帐单的表格。客户和账单有一对多的关系。 客户表包含客户mobileNo,bikeNo等的记录 账单表包含客户账单记录,包括bikeNo(外键),billdate等。 我对此有疑问:
SELECT customer.mobileNo, bill.iDate AS Expr1
FROM (customer INNER JOIN
bill ON customer.bikeNo = bill.bikeNo)
ORDER BY bill.iDate;
现在我如何获得与此查询不同的最新billdate记录和mobileNo?
答案 0 :(得分: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