sql语句面试题1
9页1、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 22005-05-10 1 2-select rq,shengfu,shengfu from #tmp where rq in(2005-05-09,2005-05-10) -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-
2、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 rq2) 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.rq3)select a.rq,a.a1 胜,b.b1 负 from (select rq,count(rq) a1 from #tmp where shengfu=胜 group by rq) a,(select rq,count(rq) b1 from #tmp where shengfu=负 group by rq)
3、b where a.rq=b.rq2.请教一个面试中遇到的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 ab then a else b end),(case when bc then b else c end ) from #tmp3.面试题:一个日期判断的sql语句?请取出tb_send表中日期(SendTime字段)为当天的所有记录?(SendTime字段为datetime型,包含日期与时间)-select * from #tmp where datediff(dd,rq,getdate()=0select * from #tmp where rq=
《sql语句面试题1》由会员小**分享,可在线阅读,更多相关《sql语句面试题1》请在金锄头文库上搜索。
2020年高考真题——理科综合(全国卷Ⅲ)+Word版含答案
2021年绝味鸭脖策划书
2021年熟食店创业方案
2021年熟食店开店策划
2021年卤菜店创业计划书
2021年周黑鸭网络营销策划方案
东大21年1月考试《现代设计方法》考核作业
谈我国行政管理效率的现状及其改观对策(论文)
单证员考试-备考辅导-复习资料:无贸易背景信用证案分析.docx
土木工程毕业生答辩自述.docx
建筑学毕业后工作状态真实写照.doc
C#代码规范(湖南大学).doc
xx区食药监局2019年工作总结及2020年工作计划
2019年中医院药物维持治疗门诊工人先锋号先进事迹
2019年度xx乡镇林长制工作总结
2019年性艾科工作计划书
2019年人才服务局全国扶贫日活动开展情况总结
关于组工信息选题的几点思考
摘了穷帽子 有了新模样
2019年某集团公司基层党支部书记培训班心得体会
2024-03-13 36页
2024-03-13 12页
2024-03-13 15页
2024-03-13 35页
2024-03-04 55页
2024-03-04 57页
2024-03-04 137页
2024-03-04 65页
2024-02-23 12页
2024-02-23 3页