以下为《SQL经典面试题及答案》的无排版文字预览,完整内容请下载
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 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 N.rq,N.R?M.尃 from ( select rq,R?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 3)select a.col001,a.a1 胜,b.b1 负 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 a.col001=b.col001 2.请教一个面试中遇到的SQL语句的查询问题 表中有A B C三列,用SQL语句实现:当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列。 ------------------------------------------ select (case when a>b then a else b end ), (case when b>c then b esle c end) from table_name 3.面试题:一个日期判断的sql语句? 请取出tb_send表中日期(SendTime字段)为当天的所有记录?(SendTime字段为datetime型,包含日期与时间) ---------------------------------- 内容过长,仅展示头部和尾部部分文字预览,全文请查看图片预览。 as '十二月份', from table2 a left join table1 b on a.dep=b.dep 8.华为一道面试题 一个表中的Id有多个记录,把所有这个id的记录查出来,并显示共有多少条记录数。 ------------------------------------------ select id, Count(*) from tb group by id having count(*)>1 select * from(select count(ID) as count from table group by ID)T where T.count>1
[文章尾部最后300字内容到此结束,中间部分内容请查看底下的图片预览]请点击下方选择您需要的文档下载。
以上为《SQL经典面试题及答案》的无排版文字预览,完整内容请下载
SQL经典面试题及答案由用户“小苹果是彬哥哥”分享发布,转载请注明出处