22,206
社区成员
发帖
与我相关
我的任务
分享
select sum(fenshuo),name from
(
select fenshuo=sum(fenshuo),name from user,fenlist where id=user_id group by name
union all
select fenshuo=sum(fenshuo),name from user,fenlist_s where id=user_id group by name
) as t
group by name
select
a.name,isnull(b.fenshuo,0)+isnull(c.fenshuo,0) as fenshuo
from
user a,
(select user_id,sum(fenshuo) as fenshuo from fenlist group by user_id)b,
(select user_id,sum(fenshuo) as fenshuo from fenlist_sgroup by user_id)c
where
a.id=b.user_id
and
a.id=c.user_id
select sum(fenshuo) as 李四的分数 from
(
select fenshuo=sum(fenshuo) from user,fenlist where id=user_id and name='李四'
union all
select fenshuo=sum(fenshuo) from user,fenlist_s where id=user_id and name='李四'
) as t
select a.name,sum(b.fenshuo) 总分
from [user] a left join
(select * from (
select [user_id],fenshuo from fenlist union all
select u_id,fenshuo from fenlist_s ) t) b
on a.id=b.[user_id]
group by a.name
select UserName,sum(results) results from
(
select '张三' as UserName,30 as results
union all
select '张三' as UserName,40 as results
) tab group by tab.UserName
?