jeocvb134
jeocvb134
2016-10-21 03:24

sql 多表联合查询,其中两张表数据字段结构一样?如何按条件查询所有项目?

sql 多表联合查询,其中两张表数据字段结构一样?如何按条件查询所有项目?

a,e两张表的字段是一样的,只是数据有不同(有的为空等),且ab的字段是用代码来显示的,要通过bcd表来匹配显示成中文名称,ae表的所有满足条件并按条件来排序显示,用了union连接,查询的结果总少了!求解!!!
select d.mc ksmc,b.fymc,a.fysl,a.fyje,b.sfbz fydj,sum(a.fysl*b.sfbz) fyzje,c.mc
from a,b,c ,d

where a.fydm=b.fydm and a.kdys=c.dm and a.kdks= d.dm and a.czks=@czks

group by d.mc ,b.fymc,a.fyje,c.mc,b.sfbz,a.fysl
union
select d.mc ksmc,b.fymc,e.fysl,e.fyje,b.sfbz fydj,sum(e.fysl*b.sfbz) fyzje,c.mc
from e,b,c ,d

where e.fydm=b.fydm and e.kdys=c.dm and e.kdks= d.dm and e.czks=@czks

group by d.mc ,b.fymc,e.fyje,c.mc,b.sfbz,e.fysl

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答