关联3个表的SQL语句怎样写?

来源:百度知道 编辑:UC知道 时间:2024/06/06 20:21:36
如:有3个表A,B,C,要显示A表中的两个字段信息(A1和A2),A1=B1,B2=C2,条件是:SUM(C3字段的值)>100
补充:还要显示SUM()的值!

select a.a1,a.a2 from a,b,c where a1=b1 and b2=c2 group by a.a1,a.a2
having sum(c.c3)>100

-----------------------------
select a.a1,a.a2,sum(c.c3) from a,b,c where a1=b1 and b2=c2 group by a.a1,a.a2
having sum(c.c3)>100

山炮

select tb1.A1,tb1.A2 from
(
select A.A1,A.A2,B.B1 from A left join B on A.A1=B.B1
) as tb1
left join
(
select C.C2,SUM(C3) as 判断字段 from C group by C2 where 判断字段>100
)
on tb1.B1=C.C2