日期:2014-05-17 浏览次数:20716 次
Create table A表(NO char(8),NAME char(50))
Insert A表
select '11111','张三'
Create table B表(NO char(8),MONEY int)
Insert B表
select '11111','1000' union all
select '11111','500' union all
select '11111','2000' union all
select '22222','300'
Create table C表(NO char(8),PRICE int,TYPE char(8))
Insert C表
select '11111','500','Retail' union all
select '11111','2000','Retail'
select A.*,SUM(C表.PRICE) as PRICE from
(select A表.NO,A表.NAME,SUM(B表.MONEY) as MONEY from A表
inner join B表 on A表.NO =B表.NO group by A表.NO ,A表.NAME) A,C表
where A.NO=C表.NO group by A.NO,A.NAME,A.MONEY
select A.NO, A.NAME,SUM(B.MONEY),SUM(C.PRICE)
from A inner join B on A.NO =B.NO
inner join C on A.NO =C.NO