需要帮助将此Oracle SQL转换为T-SQL

时间:2013-04-04 14:57:40

标签: sql sql-server oracle

需要帮助将以下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;

1 个答案:

答案 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;