DBA面试题

当前位置: 面试问题网 > DBA面试题 > Sql面试题

Sql面试题

1. 有如下表GameResult:
   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
   Select 日期,
   sum(Case score
   When ‘胜’ then 1
   Else 0
   End) as 胜,
   sum(case score
   When ‘负’ then 1
   Else 0
   end) as 负
   From GameResult
   Group by 日期
   2. 请取出tb_send表中日期(SendTime字段)为当天的所有记录。(SendTime字段为datetime型,包含日期与时间)
   select * from tb_send where datediff(day,SendTime,getdate())=0;
   3. 请用一个sql语句得出结果
   从table1,table2中取出如table3所列格式数据
   table1
   月份mon 部门dep 业绩yj
   一月份 01 10
   一月份 02 10
   一月份 03 5
   二月份 02 8
   二月份 04 9
   三月份 03 8
   table2
   部门dep 部门名称dname
   01 国内业务一部
   02 国内业务二部
   03 国内业务三部
   04 国际业务部
   table3
   部门 一月份 二月份 三月份
   01 10 null null
   02 10 8 null
   03 5 null 8
   04 null 9 null
   Select B.depId,
   sum(
   case A.mon
   when ‘一月’ then A.yeji
   end)as ‘一月’,
   sum(
   case A.mon
   when ‘二月’ then A.yeji
   end)as ‘二月’,
   sum(
   case A.mon
   when ‘三月’ then A.yeji
   end)as ‘三月’
   from table1 as A right join table2 as B on A.depId=B.depId
   group by B.depId
  
   4. 一个表中的Id有多个记录,把所有这个id的记录查出来,并显示共有多少条记录数。
   select count(*) from TableName group by ID
  
   5. 用户表userinfo,并有2个字段(id,username),其中id是自增长的,请用sql语句取出第31-40条记录。
   (注意:id也许不是连续的)
   select *from
   (
   select row_number() over(order by id) as col,* from username
   ) as A
   where A.col>= 31 and A.col=60 then 1
   end
   ) as ‘jige’,
   sum(
   case
   when result>=80 then 1
   end
   ) as ‘youxiu’,
   sum(
   case
   when result>=0 and result

【Sql面试题】相关文章

1. 一些高难度的SQL面试题

2. SQL面试题

3. MySQL面试题

4. 一个SQL面试题

5. SQL面试题

6. 一组SQL面试题

7. 一道SQL面试题

8. Sql面试题

9. 北京华建集团SQL面试题

10. MySQL面试题目集锦

本文来源:https://www.mianshiwenti.com/a13343.html

点击展开全部

《Sql面试题》

将本文的Word文档下载到电脑,方便收藏和打印

推荐程度:

进入下载页面

﹝Sql面试题﹞相关内容

「Sql面试题」相关专题

其它栏目

也许您还喜欢