【发布时间】:2015-05-22 04:58:43
【问题描述】:
我希望有人可以帮助我。我不太擅长 SQL。我看过无数其他帖子,只是无法弄清楚。我有以下数据,需要获取最近的日期。那将是 1993 年 9 月 1 日。
524 | David | NULL | 1991 | 01 | H | 1991-07-01 00:00:00.000
524 | David | NULL | 1992 | 01 | H | 1992-07-01 00:00:00.000
524 | David | NULL | 1993 | 09 | H | 1993-09-01 00:00:00.000
我尝试了以下查询,但没有返回任何结果。谁能告诉我我做错了什么?
SELECT student_crs_hist.id_num,
name_format_view.last_first_middle_suf,
year_term_table.pesc_session_type,
student_crs_hist.yr_cde,
student_crs_hist.trm_cde,
student_crs_hist.TRANSACTION_STS,
year_term_table.TRM_BEGIN_DTE
FROM student_crs_hist,
name_format_view,
year_term_table
WHERE
student_crs_hist.id_num = name_format_view.id_num
and student_crs_hist.yr_cde = year_term_table.yr_cde
and student_crs_hist.trm_cde = year_term_table.trm_cde
and student_crs_hist.TRANSACTION_STS <> 'D'
and student_crs_hist.id_num = 524
and year_term_table.TRM_BEGIN_DTE = (select max(year_term_table.TRM_BEGIN_DTE) from year_term_table)
Group By
student_crs_hist.id_num,
name_format_view.last_first_middle_suf,
year_term_table.pesc_session_type,
student_crs_hist.yr_cde,
student_crs_hist.trm_cde,
student_crs_hist.TRANSACTION_STS,
year_term_table.TRM_BEGIN_DTE
【问题讨论】:
标签: sql sql-server max