1 / 7
文档名称:

SQL经典面试题及答案.doc

格式:doc   页数:7页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

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

分享

预览

SQL经典面试题及答案.doc

上传人:yzhlya 2016/6/13 文件大小:0 KB

下载得到文件列表

SQL经典面试题及答案.doc

文档介绍

文档介绍:SQL 经典面试题及答案 1. 一道 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 222005-05-10 12------------------------------------------ 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 1else 0end)' 胜',sum(case when shengfu=' 负'then 1else 0end)' 负'from #tmp group by rq 2) select ,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 = 3)select , 胜, 负from (select col001,count(col001) a1 from temp1 where col002=' 胜'group by col001) a, (select col001,count(col001) b1 from temp1 where col002=' 负'group by col001) b where = 2. 请教一个面试中遇到的 SQL 语句的查询问题表中有 ABC三列,用SQL 语句实现:当 A列大于 B列时选择 A列否则选择 B 列,当 B列大于 C列时选择 B列否则选择 C列。------------------------------------------ select (case when a>b then aelse bend ), (case when b>c then besle cend) from table_name 3. 面试题:一个日期判断的 sql 语句? 请取出 tb_send 表中日期(SendTime 字段)为当天的所有记录?(