select t1.name,t1.id,t2.name as listtwo,t2.id as idtwo form
( select name ,id ,time,joy form table1
) t1,
( select name ,id ,time,joy form table1
) t2
where t1.name=t2.name and
t1.id=t2.id
问题是T1,T2里的数据是有重复的。
name id listtwo idtwo
25 12 5 12
25 12 5 12
24 12 4 12
24 12 10 10
怎样写能把第一,二项,合成:
25 12 10 12
------解决方案--------------------
select name,id,sum(listtwo) listtwo, idtwo
from
(select t1.name,t1.id,t2.name as listtwo,t2.id as idtwo form
( select name ,id ,time,joy form table1
) t1,
( select name ,id ,time,joy form table1
) t2
where t1.name=t2.name and
t1.id=t2.id
) t
group by t.name,id,listtwo,idtwo;