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

求数据统计
表名:allreecord
字段
id     hwin     dwin     draw     a     b

SELECT   Count(hwin)   AS   i
FROM   all_odds
WHERE   (a-b> 0)   AND   hwin   Between   1.4   And   1.5

SELECT   Count(hwin)   AS   i
FROM   all_odds
WHERE   (a-b=0)   AND   hwin   Between   1.4   And   1.5

SELECT   Count(hwin)   AS   i
FROM   all_odds
WHERE   (a-b <0)   AND   hwin   Between   1.4   And   1.5

----------------------------------------------
如何把上面的SQL写成一句,且查询出来的数据显示为
count1     count2     count3
  结果         结果         结果
----------------------------------------------

------解决方案--------------------
select
sum(case when a-b> 0 then 1 else 0 end) as count1,
sum(case when a-b=0 then 1 else 0 end) as count2,
sum(case when a-b <0 then 1 else 0 end) as count3
from all_odds
where hwin between 1.4 and 1.5