当前位置: 代码迷 >> Sql Server >> 急救:又是Join又是Sum的查询语句,该怎么解决
  详细解决方案

急救:又是Join又是Sum的查询语句,该怎么解决

热度:12   发布时间:2016-04-27 16:14:00.0
急救:又是Join又是Sum的查询语句
三个表:

A   (id,字段1,字段2,字段3)

B     (id,字段5,字段6,字段7)

C   (id,字段8,字段9,字段10)

已知:
A表   id不重复,主键

B表
sum(字段5)   as   zje1     group   by   B.id

C表
sum(字段8)   as   zje2     group   by   C.id


请问如何显示出

(A   (id,字段1,字段2,字段3,zje1,   zje2))


------解决方案--------------------
select a.*,b.zje1,c.zje2
from tableA as a
left join
(select id,sum(字段5) as zje1 from tableB group by id) as b on a.id = b.id
left join
(select id,sum(字段8) as zje2 from tableC group by id) as c on a.id = c.id
  相关解决方案