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

原文地址:https://www.cnblogs.com/matengfei123/p/8862787.html