常见SQL笔试题分析和总结.docxVIP

  • 14
  • 0
  • 约6.19千字
  • 约 14页
  • 2023-10-23 发布于上海
  • 举报
SQL笔试题 统计查询 SQL 练习 数据库中表结构如下,字段分别任rg(日期),shengfu(胜负),考察group by 语句的使用: 2005-05-09 胜 2005-05-09 胜 2005-05-09 负 2005-05-09 负 2005-05-10 胜 2005-05-10 负 2005-05-10 负 如果要生成下列结果, 该如何写sql 语句? 胜负 2005-05-09 2 2 2005-05-10 1 2 答案: select rq, sum(case when shengfu= 胜 then 1 else 0 end) 胜,sum(case when shengfu=负 then 1 else 0 end)负 from #tmp group by rq select N.rq,N.胜,M.负from ( select rq,胜=count(*) from #tmp where shengfu=胜group by rq)N inner join (select rq, 负=count(*) from #tmp where shengfu= 负group by rq)M on N.rq=M.rq select a.col001,a.a1 胜 ,b.b1 负 from (select col001,count(col001) a1 from temp1 whe

文档评论(0)

1亿VIP精品文档

相关文档