我想转换此查询。 在sql中使用它。 我不知道如何使用las和max与组
SELECT main.id,
main.rep1,
main.NAME,
main.family,
main.ostan,
main.city,
main.telhome,
Max(report.nextc) AS maxofnextc,
main.status,
Last(report.date) AS lastofdate,
Last(report.connect) AS lastofconnect,
main.hospital,
main.[Bimeh-Not],
main.tamin,
main.khadamat,
main.niroo,
main.emdad,
main.takmili,
main.sayer,
main.darmangar
FROM main
INNER JOIN report
ON main.id = report.id
GROUP BY main.id,
main.rep1,
main.NAME,
main.family,
main.ostan,
main.city,
main.telhome,
main.status,
main.hospital,
main.[Bimeh-Not],
main.tamin,
main.khadamat,
main.niroo,
main.emdad,
main.takmili,
main.sayer,
main.darmangar
HAVING ((( main.rep1) LIKE "BEN")
AND (( Max(report.nextc))<=[تاريخ روز جاري را وارد نماييد])
AND ( main.status)<>4
AND ( main.status)<>1
AND ( main.status)<>5))
ORDER BY max(report.nextc) DESC ,
main.status,
last(report.connect);