图片中的第二题
我只能查询到这一步,行数多了,列数少一个,怎么用子查询做到啊?
select t.日期, (select count(*) from 表名 t1 where t.日期 = t1.日期 and t1.战绩 = '胜') as '胜',(select count(*) from 表名 t1 where t.日期 = t1.日期 and t1.战绩 = '负') '负' FROM 表名 t group by t.日期
你再把结果分组试试。
行转列
SELECT a 日期 , sum(case b when '胜' then 1 else 0 end ) 胜 ,
sum(case b when '负' then 1 else 0 end) 负
FROM tesgt1
GROUP BY a