本文介绍了从临时表变更的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在更新报告(不是由我创建的)并且有一个使用临时表。 1。有没有办法在不使用临时表的情况下更好地编写查询? 2。我应该在哪里添加代码以包含另一个表中的另一列? (例如:-jOIN rcitem on rcitem.identity_column = glmast.identity_column) DECLARE @StartDate DATETIME DECLARE @EndDate DATETIME 选择rcmast.freceiver,rcmast.fdaterecv,rcmast.fpono,rcmast.fpacklist,rcmast.fvendno, rcitem.fpartno,rcitem.fpartrev,rcitem.fpoitemno,rcitem.fqtyrecv,rcitem.fmeasure, rcitem.fcategory INTO#rc1 来自rcitem 加入rcmast on rcitem.freceiver = rcmast.freceiver 其中rcmast.fdaterecv介于(@StartDate)和(@EndDate)$ b之间 $ b选择#rc1.freceiver,fdaterecv,#rc1.fpono,#rc1.fpoitemno,fpacklist,fvendno,#rc1.fpartno,#rc1.fpartrev,fqtyrecv,fucostonly,sum(fqtyrecv * fucostonly)作为最终成本,#rc1.fmeasure,#rc1.fcategory INTO#po1 来自#rc1 加入poitem#rc1.fpono +#rc1.fpoitemno = poitem.fpono + poitem .fitemno group by#rc1.freceiver,fdaterecv,#rc1.fpono,#rc1.fpoitemno,fpacklist,fvendno,#rc1.fpartno, #r c1.fpartrev,fqtyrecv,fucostonly,#rc1.fmeasure,#rc1.fcategory 选择#po1.freceiver,#po1.fpono,fpoitemno,#po1.fdaterecv,#po1。 fvendno,rcmast.fcompany,#po1.fpacklist,#po1.fpartno, coalesce(inmast.fdescript,'')如fdescript,fqtyrecv,fucostonly,finalcost,#po1.fmeasure,#po1.fcategory,pocatg。 fglacct 来自#po1 离开加入inmast#po1.fpartno +#po1.fpartrev = inmast.fpartno + inmast.frev 加入rcmast#po1.freceiver = rcmast.freceiver 其中#po1.fpono不喜欢'c%'和fucostonly<> 0和pocatg.fdesc不喜欢'%not use%'由freceiver订购 drop table#rc1 drop table#po1 谢谢! 我听到了,我忘记了。我看,我记得。我明白了。解决方案 I'm currently updating reports (not created by me) and have one that uses Temp Tables.1. Is there a way to better write the query without using Temp Tables?2. Where should I add code to include one more column from another table? (example: --JOIN rcitem on rcitem.identity_column = glmast.identity_column)DECLARE @StartDate DATETIMEDECLARE @EndDate DATETIMEselect rcmast.freceiver, rcmast.fdaterecv, rcmast.fpono, rcmast.fpacklist, rcmast.fvendno,rcitem.fpartno, rcitem.fpartrev, rcitem.fpoitemno, rcitem.fqtyrecv, rcitem.fmeasure,rcitem.fcategoryINTO #rc1from rcitemjoin rcmast on rcitem.freceiver = rcmast.freceiverwhere rcmast.fdaterecv between (@StartDate) and (@EndDate)select #rc1.freceiver, fdaterecv, #rc1.fpono, #rc1.fpoitemno, fpacklist, fvendno, #rc1.fpartno,#rc1.fpartrev, fqtyrecv, fucostonly, sum(fqtyrecv * fucostonly) as finalcost, #rc1.fmeasure, #rc1.fcategoryINTO #po1from #rc1join poitem on #rc1.fpono + #rc1.fpoitemno = poitem.fpono + poitem.fitemnogroup by #rc1.freceiver, fdaterecv, #rc1.fpono, #rc1.fpoitemno, fpacklist, fvendno, #rc1.fpartno, #rc1.fpartrev, fqtyrecv, fucostonly, #rc1.fmeasure, #rc1.fcategoryselect #po1.freceiver, #po1.fpono, fpoitemno, #po1.fdaterecv, #po1.fvendno, rcmast.fcompany, #po1.fpacklist, #po1.fpartno,coalesce(inmast.fdescript,' ') as fdescript, fqtyrecv, fucostonly, finalcost, #po1.fmeasure,#po1.fcategory,pocatg.fglacctfrom #po1left join inmast on #po1.fpartno + #po1.fpartrev = inmast.fpartno + inmast.frevjoin rcmast on #po1.freceiver = rcmast.freceiverwhere #po1.fpono not like 'c%' and fucostonly <> 0 and pocatg.fdesc Not Like '%not use%'Order by freceiverdrop table #rc1drop table #po1Thanks!I hear and I forget. I see and I remember. I do and I understand. 解决方案 这篇关于从临时表变更的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-18 22:41