1 / 9
文档名称:

SQL语句面试题范文.docx

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

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

分享

预览

SQL语句面试题范文.docx

上传人:buzaiwuzhuang123 2020/2/5 文件大小:25 KB

下载得到文件列表

SQL语句面试题范文.docx

相关文档

文档介绍

文档介绍: SQL 语句面试题,关于 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 22005-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 whenshengfu='负' then 1 else 0 end)'负' from #tmpgroup by rq2) 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 =)select , 胜, 负 from (select rq,count(rq) a1 from #tmp whereshengfu='胜' group by rq) a,(select rq,count(rq) b1 from #tmp where shengfu='负' group by rq) b  = SQL 语句的查询问题表中有 A B C 三列,用 SQL 语句实现:当 A 列大于 B 列时选择 A 列否则选择 B 列,当 B 列大于 C 列时选择 B 列否则选择 C 列。------------------------------------------create table #tmp(A int,B int,C int)insert into #tmp values('10','20','30')--insert into #tmp values('10','30','20')--insert into #tmp values('40','10','20')select * from #tmpselect (case when a>b then a else b end),(case wh