需要帮助将以下Oracle SQL查询转换为T-SQL查询
SELECT rh.user_name, rh.report_name, rh.report_run_date
FROM report_history rh,
(SELECT max(report_run_date) as maxdate, report_name
FROM report_history
GROUP BY report_name) maxresults
WHERE rh.report_name = maxresults.report_name
AND rh.report_run_date= maxresults.maxdate;
答案 0 :(得分:2)
尝试:
SELECT
rh.user_name,
rh.report_name,
rh.report_run_date
FROM
report_history rh
INNER JOIN
(
SELECT
max(report_run_date) as maxdate,
report_name
FROM
report_history
GROUP BY
report_name
) maxresults
ON rh.report_name = maxresults.report_name
AND rh.report_run_date= maxresults.maxdate;