select t.userid,sum(t.score) 
from 
   (select userid,score from talbea
    union
    select userid,score from talbeb
    union
    select userid,score from talbec
    ) t
group by t.suerid

解决方案 »

  1.   

    select
        userid,score=sum(score)
    from
        (select * from 表a
         union all
         select * from 表b 
         union all
         select * from 表c) d
    group by
        userid
    order by 
        score
      

  2.   

    declare @a table(userid int,score int)
    insert @a values(1,10)
    insert @a values(2,20)
    insert @a values(4,10)declare @b table(userid int,score int)
    insert @b values(2,10)
    insert @b values(3,20)declare @c table(userid int,score int)
    insert @c values(1,10)select userid,sum(score) as score
    from (
    select * from @a
    union all
    select * from @b
    union all
    select * from @c) a
    group by userid
    order by score desc
      

  3.   

    select
        userid,score=sum(score)
    from
        (select * from 表a
         union all
         select * from 表b 
         union all
         select * from 表c) d
    group by
        userid
    order by 
        score desc
      

  4.   

    还要显示 userinfo 表里面 userid 相同的记录的 usersex 字段,怎么加?
      

  5.   

    select t.*,
           [sex]=(select usersex from userinfo where userid=t.userid)
    from
        (
          select
          userid,score=sum(score)
          from
             (select * from 表a
              union all
              select * from 表b 
              union all
              select * from 表c) d
          group by
                 userid
          order by 
                   score    )t
      

  6.   

    或者:
    select t.*,
           U.usersex
    from
        (
          select
          userid,score=sum(score)
          from
             (select * from 表a
              union all
              select * from 表b 
              union all
              select * from 表c) d
          group by
                 userid
          order by 
                   score    )t
    join userinfo U on U.userid=t.userid
      

  7.   

    select t.*,
           [sex]=(select usersex from jgame_userinfo where userid=t.userid)from
    (
    select
        userid,score=sum(score)
    from
        (select userid,score from jgame_aq_score
         union all
         select userid,score from jgame_cdd_score 
         union all
         select userid,score from jgame_chess_score
         union all
         select userid,score from jgame_ddz_score
         union all
         select userid,score from jgame_gz_score
         union all
         select userid,score from jgame_jq_score
         union all
         select userid,score from jgame_mj_score
         union all
         select userid,score from jgame_pdk_score
         union all
         select userid,score from jgame_sdy_score
         union all
         select userid,score from jgame_sgjq_score
         union all
         select userid,score from jgame_sh_score
         union all
         select userid,score from jgame_tlj_score
         union all
         select userid,score from jgame_wq_score
         union all
         select userid,score from jgame_wzq_score
         union all
         select userid,score from jgame_xq_score) 
    d
    group by
        userid
    order by 
        score desc) t
    服务器: 消息 1033,级别 15,状态 1,行 40
    除非同时指定了 TOP,否则 ORDER BY 子句在视图、内嵌函数、派生表和子查询中无效。
      

  8.   

    try:select t.*,
           [sex]=(select usersex from jgame_userinfo where userid=t.userid)from
    (
    select top 100 percent 
        userid,score=sum(score)
    from
        (select userid,score from jgame_aq_score
         union all
         select userid,score from jgame_cdd_score 
         union all
         select userid,score from jgame_chess_score
         union all
         select userid,score from jgame_ddz_score
         union all
         select userid,score from jgame_gz_score
         union all
         select userid,score from jgame_jq_score
         union all
         select userid,score from jgame_mj_score
         union all
         select userid,score from jgame_pdk_score
         union all
         select userid,score from jgame_sdy_score
         union all
         select userid,score from jgame_sgjq_score
         union all
         select userid,score from jgame_sh_score
         union all
         select userid,score from jgame_tlj_score
         union all
         select userid,score from jgame_wq_score
         union all
         select userid,score from jgame_wzq_score
         union all
         select userid,score from jgame_xq_score) 
    d
    group by
        userid
    order by 
        score desc) t
      

  9.   

    或者去掉order by score desc