我试图通过仅返回年份将Max(年)从日期字段变为Varchar字段 我希望有人可以提供帮助。
这就是我到目前为止所做的。
UPDATE MasterDraft
SET
Last_title_changed = (select Max((deed_dt) )
From APPRAISAL_Deed_History )
WHERE MasterDraft.Prop_ID = APPRAISAL_Deed_History.prop_id
这是我的源表:
+---------+------------+
| prop_id | deed_dt |
+---------+------------+
| 40 | 1988-07-22 |
| 40 | 1984-03-01 |
| 40 | 2005-07-12 |
| 40 | 1983-07-01 |
| 40 | 1992-01-31 |
| 40 | 1983-01-01 |
| 40 | 1990-01-31 |
+---------+------------+
MasterDraft.Last_title_Changed上的输出应为2005
答案 0 :(得分:1)
那应该是Max(YEAR(deed_dt))
编辑:那么你想更新所有记录并使用prop id的最大年份?然后将where子句移动到子选择。在内部查询之外不知道APPRAISAL_Deed_History.prop_id。
UPDATE MasterDraft SET Last_title_changed = ( select Max( Year(deed_dt) ) from APPRAISAL_Deed_History where APPRAISAL_Deed_History.prop_id = MasterDraft.Prop_ID );
答案 1 :(得分:0)
UPDATE MasterDraft
SET Last_title_changed = Max(YEAR(deed_dt)
From APPRAISAL_Deed_History INNER JOIN MasterDraft
WHERE MasterDraft.Prop_ID = APPRAISAL_Deed_History.prop_id