mysql的子查询的提高

统计胜负结果的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-02    1       1

 

posted @ 2018-04-17 11:48  matengfei  阅读(167)  评论(0编辑  收藏  举报