一个简单的查询,求高手指点!
--DROP TABLE ACREATE TABLE A(id int primary key identity(1,1),score decimal(18,2))--DROP TABLE BCREATE TABLE B(id int primary key identity(1,1),pid int , --A表的IDmath decimal(18,2),english decimal(18,2))SELECT * FROM AINSERT INTO A VALUES(50)SELECT * FROM BINSERT INTO B VALUES(1,5,5)INSERT INTO B VALUES(1,5,5)INSERT INTO B VALUES(1,15,15)--想获得子表中math总分想获得SQL语句取得以下结果id score math----------- ---------------------------------------1 50.00 ?
select #a.id,#a.score,SUM(#b.math) as math from #A,#B where #A.id = #B.pid group by #A.id,#A.score
[解决办法]
select A.ID,A.Score,SUM(math)as math from A inner Join B on A.id=B.pid group by A.id,A.score
[解决办法]
select a.ID,a.score,sum(math) as mathfrom Ainner join B on a.id=b.pidgroup by a.ID,a.score
[解决办法]
楼主烧糊涂了,开始胡说八道了
[解决办法]