储存过程多个表比较的修改!

v1srine 2011-05-12 03:29:12
列子:
select a.*,b.* from #temppd a left join #tempbom b on a.item_code=b.item_code

这句代码 还可以加第三个表嘛?
怎么加。
这里只有两个表对比。但是我想在这段代码里面加上第三个表对比请问怎么加?
我试了很久都没结果!
求答案!



select a.mater_code,a.pdwet,c.jieguo as gxwet,a.mtwet,a.mtgmawet,b.item_order from
(select a.mater_code,sum(case when TAG='A' then wet else 0 end) as pdwet,
sum(case when TAG='包根' then wet else 0 end) as gxwet,
sum(case when TAG='GC' then wet else 0 end) AS mtwet,
sum(case when TAG='GMA' then wet else 0 end) AS mtGMAwet
from
(select b.mater_code,sum(round(a.wet*b.len_xs,2)) as wet,tag from #temppd a left join #tempbom b on a.item_code=b.item_code
where b.class_code=2 and b.mater_code is not null group by b.mater_code,a.tag
union all
select b.mater_code,sum((a.wet*b.len_xs/100)) as wet, '包根' AS tag from #temppd_gx a left join tempbom b on a.item_code=b.item_code
where b.class_code=1 and b.mater_code is not null group by b.mater_code
union all
select item_code as mater_code,wet,packno AS tag from #temppd_mt
) a group by a.mater_code,a.tag
)a left join fourk.dbo.item b on a.mater_code=b.item_code
order by item_order





我这段代码怎么加!
c.jieguo as gxwet
这个C 我想加个表!
但是不知道怎么加上去
这是储存过程!
...全文
89 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jxqn_liu 2011-05-12
  • 打赏
  • 举报
回复

子查询嵌套子查询,建议优化下,把一些查询改成视图等
再说你要加的C表要加那个位置得看你得实现啥功能先。
v1srine 2011-05-12
  • 打赏
  • 举报
回复
表C。.
C 是缩写

#tempssS c

这个是表C。请问怎么加?
wing7742 2011-05-12
  • 打赏
  • 举报
回复
没看到你表C在哪
v1srine 2011-05-12
  • 打赏
  • 举报
回复
2楼,我想知道我的代码怎么加?

你的那个我老早试过了,我加不上!

希望你能帮帮忙
Billy 2011-05-12
  • 打赏
  • 举报
回复
select * 
from a left join b on a.id=b.id
left join c on a.id=c.id
left join d on b.id=d.id


可以任意加多少

22,207

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧