日期:2014-05-18  浏览次数:20490 次

求教一个SQL语句~
情况是这样的,有个表:
table1
type     int
point   int

现在想在一句SQL里求得如下几个值:
type   =0   时的纪录总数
type   =0   时的point数之和(sum)
type   =0   AND   point=   10   时的纪录数
type   =0   AND   point=   20   时的纪录数

请问有可能吗?

------解决方案--------------------
select count(type),sum(point),纪录数1=sum(case when point= 10 then 1 else 0 end),纪录数2=sum(case when point= 20 then 1 else 0 end)
from table1
where type=0
------解决方案--------------------
select
count(*),
sum(point),
sum(case point when 10 then 1 else 0 end),
sum(case point when 20 then 1 else 0 end)
from

where
type=0
------解决方案--------------------
select count(1),sum(point),sum(case when point=10 then 1 else 0 end),sum(case when point=20 then 1 else 0 end) from table1 where type=0
------解决方案--------------------
declare @table1 table(type int,point int)

insert @table1 select 0 ,20
union all select 0 ,20
union all select 0 ,10
union all select 0 ,10

select count(1),sum(point),(select count(1) from @table1 where type =0 AND point= 10)
,(select count(1) from @table1 where type =0 AND point= 20)
from @table1
where type =0