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
from
(select userid,score from talbea
union
select userid,score from talbeb
union
select userid,score from talbec
) t
group by t.suerid
解决方案 »
- 不用select其它列名,如何select 表中除了id以外的所有列,
- 数据库连接问题(简单)
- 求教except操作原理
- 想把Window form界面登陆名和密码存储在数据库,数据库存储过程怎么写
- 這個sql怎麼寫, 根據時間取最高版本
- 触发器执行错误
- sp_updateextendedproperty 的问题?
- SQLSERVER2K跟踪错误
- 合并复制错误, uniqueidentifier 列的索引出错???
- 我要在存储过程中select另一数据库中的某个表,应该怎么写?
- sql在线帮助网址是多少,怎么在SQL SERVER2000中找不到链接呀?
- 怎样用查询语句把两个不同表的内容进行合并?
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
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
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
[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
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
[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 子句在视图、内嵌函数、派生表和子查询中无效。
[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