设为首页收藏本站

嘻皮客娱乐学习网

 找回密码
 中文注册
搜索
打印 上一主题 下一主题
开启左侧

[面试题库] Sql面试题

[复制链接]
跳转到指定楼层
楼主
发表于 2014-11-30 13:10:01 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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
回复

使用道具 举报

小黑屋|手机版|嘻皮客网 ( 京ICP备10218169号|京公网安备11010802013797  

GMT+8, 2024-6-1 21:11 , Processed in 0.178842 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表