我想通过sql语句获取2个组的总分数,及已获得的分数,并从左到右,按值得大小横向排序进行排序
如这样结果 4560 4549.5 3617 3510
select distinct
(select sum((分数+isnull(技术分数,0))) as 总分数 from [WORK].[dbo].[v3] where groupid=20
and ztstartTime between '2014-03-01' and '2015-02-05')as zf1,
(select sum((分数+isnull(技术分数,0))) as 总分数 from [WORK].[dbo].[v3] where groupid=21
and ztstartTime between '2014-03-01' and '2015-02-05')as zf2,
(select sum(convert(float,分数)) as score from WorkIng where leaderID=127 and
ztstartTime between '2014-03-01' and '2015-02-05' and done='true')as ydf1,
(select sum(convert(float,分数)) as score from WorkIng where leaderID=128 and
ztstartTime between '2014-03-01' and '2015-02-05' and done='true')as ydf2
from [WORK].[dbo].[v3] as a where groupID<>0 ORDER BY zf1 asc
这样写太繁琐,请帮忙简化一下写法,谢谢
------解决思路----------------------
--那马,统一使用视图的数据查询就可以了:
select distinct
sum(case when groupid=20 then 分数+isnull(技术分数,0) else 0 end) as zf1,
sum(case when groupid=20 then 分数+isnull(技术分数,0) else 0 end) as zf2,
sum(case when leaderID=127 and done='true' then convert(float,分数) else 0 end) as ydf1,
sum(case when leaderID=128 and done='true' then convert(float,分数) else 0 end) as ydf2
from [WORK].[dbo].[v3] as a
where groupID<>0
and ztstartTime between '2014-03-01' and '2015-02-05'