`
810364804
  • 浏览: 787578 次
文章分类
社区版块
存档分类
最新评论

统计胜负结果的SQL语句

 
阅读更多

统计胜负结果的SQL语句,这里采用子查询来实现。

表结构和数据

date result

2011-02-01 胜

2011-02-01 负

2011-02-01 胜

2011-02-02 胜

2011-02-02 负

采用子查询

select date,(select count(*) from table1 where date = t.date and result = '胜') as '胜'
,(select count(*) from table1 where date = t.date and result = '负') as '负'
from table1 as t group by date;

查询出来的结果:

date 胜 负

2011-02-01 2 1

2011-02-0211

听同学和同事说,这道题有很多公司都作为SQL的笔试题。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics