数据库面试题-胜负统计
mysql 第一种解决方法
SELECT datetime 日期,
SUM(if(result='胜',1,0)) 胜,
SUM(if(result='负',1,0)) 负
from t_nba
group by datetime
通用sql,使用left join完成
SELECT t.*,t2.fu from
(SELECT DISTINCT(t_nba.datetime) datetime, t1.sheng from t_nba
LEFT JOIN
(
SELECT datetime , COUNT(*) as sheng from t_nba
where result='胜' GROUP BY datetime
) as t1
on t_nba.datetime = t1.datetime
) t LEFT JOIN
(
SELECT datetime , COUNT(*) as fu from t_nba
where result='负' GROUP BY datetime
) as t2
ON t.datetime = t2.datetime