1 / 4
文档名称:

sql数据库面试题及答案.docx

格式:docx   大小:17KB   页数:4页
下载后只包含 1 个 DOCX 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

sql数据库面试题及答案.docx

上传人:baibai 2022/5/15 文件大小:17 KB

下载得到文件列表

sql数据库面试题及答案.docx

文档介绍

文档介绍:sql数据库面试题及答案
sql数据库面试题及答案

=txt>,关于group by
表内容:
2005-05-09 胜
2005-05-09

sql数据库面试题及答案
sql数据库面试题及答案

=txt>,关于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
------------------------------------------
create table #tmp(rq varchar(10),shengfu nchar(1))
insert into #tmp values(2005-05-09,胜)


insert into #tmp values(2005-05-09,胜)
insert into #tmp values(2005-05-09,负)
insert into #tmp values(2005-05-09,负)
insert into #tmp values(2005-05-10,胜)
insert into #tmp values(2005-05-10,负)
insert into #tmp values(2005-05-10,负)
1)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
2) select ,, 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 =
3)select , 胜, 负 from
(select col001,count(col001) a1 from temp1 where col002=胜group