可以让这个 SQL 语句执行得更好吗?
我有一个 SQL 语句用于将编辑从一个表合并到另一个表。也就是说
UPDATE f
SET f.AUDAPLCDE = m.AUDAPLCDE, f.AUDSTF_NO = m.AUDSTF_NO,
f.AUDUPD_ID = m.AUDUPD_ID, f.AUDUPDDTE = m.AUDUPDDTE,
f.UNTTYP = m.UNTTYP, f.UNTSTM_NO = m.UNTSTM_NO,
f.UNTIND = f.UNTIND, f.UNQ = m.UNQ,
f.TRNCTL_NO = m.TRNCTL_NO, f.TRN_NO = m.TRN_NO,
f.STAEVT = m.STAEVT, f.SPSDTE = m.SPSDTE,
f.RVRRSN = m.RVRRSN, f.AUDUPDTME = m.AUDUPDTME,
f.RHTTYP = m.RHTTYP, f.ALCADJ = m.ALCADJ,
f.RESFAC = m.RESFAC, f.PRTDTE = m.PRTDTE,
f.POLREF = m.POLREF, f.OUTFAC = m.OUTFAC,
f.OTHBENQTY = m.OTHBENQTY, f.ORIIND = m.ORIIND,
f.ORIDTE = m.ORIDTE, f.INRTYP = m.INRTYP,
f.INRREF = m.INRREF, f.FNDTRNTYP = m.FNDTRNTYP,
f.FNDSUBTYP = m.FNDSUBTYP, f.FNDREF = m.FNDREF,
f.FNDPRC = m.FNDPRC, f.EVTUNQ = m.EVTUNQ,
f.EVTTRN_NO = m.EVTTRN_NO, f.EFVDTE = m.EFVDTE,
f.DUEDTE = m.DUEDTE, f.CTBPCT = m.CTBPCT,
f.CO_REF = m.CO_REF, f.CAL_YR = m.CAL_YR,
f.BONSUBTYP = f.BONSUBTYP, f.BONSTA = m.BONSTA,
f.BONDCL_YR = m.BONDCL_YR, f.BON_YR = m.BON_YR,
f.BENTYP = m.BENTYP, f.BENREF = m.BENREF,
f.BENQTY2 = m.BENQTY2, f.BENQTY1 = m.BENQTY1,
f.AMT = m.AMT, f.ALCRTE = m.ALCRTE
FROM FI700 f
INNER JOIN MERGEDATA_FI700 m ON m.FI700_UNIQUE_ID = f.FI700_UNIQUE_ID
AND m.SSIS_UPDATE_TYPE = 'U'
AND m.SSIS_TIMESTAMP in (SELECT max(mm.SSIS_TIMESTAMP)
FROM MERGEDATA_FI700 mm
WHERE mm.FI700_UNIQUE_ID = m.FI700_UNIQUE_ID
AND mm.SSIS_UPDATE_TYPE = 'U')
,真的,我只是想获取最新的编辑(通过时间戳)字段,因为这将包含所有累积的编辑。我很确定这可以做得更好,即以某种方式将 SELECT max(mm.SSIS_TIMESTAMP)... 嵌套查询集成到其上方的联接中。
有什么想法吗?
I have a SQL statement for merging edits from one table to another. I.e.
UPDATE f
SET f.AUDAPLCDE = m.AUDAPLCDE, f.AUDSTF_NO = m.AUDSTF_NO,
f.AUDUPD_ID = m.AUDUPD_ID, f.AUDUPDDTE = m.AUDUPDDTE,
f.UNTTYP = m.UNTTYP, f.UNTSTM_NO = m.UNTSTM_NO,
f.UNTIND = f.UNTIND, f.UNQ = m.UNQ,
f.TRNCTL_NO = m.TRNCTL_NO, f.TRN_NO = m.TRN_NO,
f.STAEVT = m.STAEVT, f.SPSDTE = m.SPSDTE,
f.RVRRSN = m.RVRRSN, f.AUDUPDTME = m.AUDUPDTME,
f.RHTTYP = m.RHTTYP, f.ALCADJ = m.ALCADJ,
f.RESFAC = m.RESFAC, f.PRTDTE = m.PRTDTE,
f.POLREF = m.POLREF, f.OUTFAC = m.OUTFAC,
f.OTHBENQTY = m.OTHBENQTY, f.ORIIND = m.ORIIND,
f.ORIDTE = m.ORIDTE, f.INRTYP = m.INRTYP,
f.INRREF = m.INRREF, f.FNDTRNTYP = m.FNDTRNTYP,
f.FNDSUBTYP = m.FNDSUBTYP, f.FNDREF = m.FNDREF,
f.FNDPRC = m.FNDPRC, f.EVTUNQ = m.EVTUNQ,
f.EVTTRN_NO = m.EVTTRN_NO, f.EFVDTE = m.EFVDTE,
f.DUEDTE = m.DUEDTE, f.CTBPCT = m.CTBPCT,
f.CO_REF = m.CO_REF, f.CAL_YR = m.CAL_YR,
f.BONSUBTYP = f.BONSUBTYP, f.BONSTA = m.BONSTA,
f.BONDCL_YR = m.BONDCL_YR, f.BON_YR = m.BON_YR,
f.BENTYP = m.BENTYP, f.BENREF = m.BENREF,
f.BENQTY2 = m.BENQTY2, f.BENQTY1 = m.BENQTY1,
f.AMT = m.AMT, f.ALCRTE = m.ALCRTE
FROM FI700 f
INNER JOIN MERGEDATA_FI700 m ON m.FI700_UNIQUE_ID = f.FI700_UNIQUE_ID
AND m.SSIS_UPDATE_TYPE = 'U'
AND m.SSIS_TIMESTAMP in (SELECT max(mm.SSIS_TIMESTAMP)
FROM MERGEDATA_FI700 mm
WHERE mm.FI700_UNIQUE_ID = m.FI700_UNIQUE_ID
AND mm.SSIS_UPDATE_TYPE = 'U')
Really, I'm just trying to take the latest edit (by the TimeStamp) field, as this will contain all the cumulative edits. I'm pretty sure this can be made to perform better, i.e. somehow integrate the SELECT max(mm.SSIS_TIMESTAMP)
... nested query into the join above it.
Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有两件小事 - 但不确定它们是否有很大区别:
1)SSIS_TIMESTAMP 上是否有可以使用的索引?
2)由于您选择了 MAX 值,因此可以使用等号而不是“IN”运算符:
Marc
Two small things - not sure if they make a big difference, though:
1) Is there an index on SSIS_TIMESTAMP that can be used??
2) Since you're selecting the MAX value, you could use an equal sign instead of "IN" operator:
Marc