m0_58765004
2021-07-21 19:20
采纳率: 85.7%
浏览 18

复杂的SQL语句,查询一张表的结果生成另外一张表的字段

img

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • Aganstrong 2021-07-21 19:52
    已采纳
    
    select bsrq as '比赛日期', SUM(sl) as '胜', SUM(sb) as '负' from (
      select match_date as bsrq, count(Result) as sl, 0 as sb from match_record  where Result = '胜' group by match_date 
      union all
      select match_date as bsrq, 0 as sl, count(Result) as sb from match_record  where Result = '负' group by match_date 
    ) t group by bsrq 
    

    剩下的可以再优化

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题