求助sql跨表查询
sql吧
全部回复
仅看楼主
level 1
有两个表,a表有xh,xm,lxnd;b表有xh,xmdm,sjje,b表xh有多条记录,要求查询显示xh,xm,sjje按xh显示sum(sjje) where lxnd=值
2024年10月22日 07点10分 1
level 1
两表关联?
2024年10月24日 00点10分 2
level 1
select a.xh,xm,sum(sjje) from
(select xh,xm,lxnd from a ) a
left join
(select xh,xmdm,sjje from b ) b
on a.xh = b.xh
where lxnd = '值'
order by a.xh,xm
2024年10月24日 00点10分 3
level 7
楼上写的是错的,别误导别人
2024年10月25日 07点10分 4
level 1
select a.xh,a.xm,b.sjje from a
join
(select xh,sum(sjje) as sjje from b group by xh) as b on a.xh=b.xh
2024年11月12日 09点11分 5
把B表的sjje字段根据xh分类汇总后作为数据源去和A表join,where条件自己加一下就行了
2024年11月12日 09点11分
level 6
用视图
2024年12月10日 23点12分 6
1