php - 请教一条sql语句的写法?
给我你的怀抱
给我你的怀抱 2017-05-16 13:00:01
0
2
680

现有两个表格,表格1 ->T1:
id name time type
1 A hh 1
2 B kk 1
3 c vv 2
表格2-> T2:
id pid every
1 1 20
2 1 10
3 1 5
4 2 15
5 2 10
6 3 25
7 3 35
其中表格2的pid关联表格1的id,当type=1时,希望得到如下两条数据:
1 A hh 20+10+5(35)
2 B kk 15+10 (25)
求教sql语句该怎么写啊,谢谢!PS:用的是thinkPHP框架

给我你的怀抱
给我你的怀抱

reply all(2)
世界只因有你
select t1.id, t1.name, t1.time, sum(t2.every)
from t1
inner join t2 on t1.id=t2.pid
group by t1.id, t1.name, t1.time
洪涛
SELECT T1.id,T1.name,T1.time,SUM(T2.every) 
FROM T1 
INNER JOIN T2 ON T1.id = T2.pid 
GROUP BY T1.id;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!