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
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面试题﹞相关内容
- 十一个高级MySql面试题
- mysql_pconnect()和mysql_connect()有什么区别
- 写一个在SQL Server创建表的SQL语句
- C#和SQL Server的面试题
- 一道写SQL的面试题和答案
- 一道SQL存储过程面试题
- 几个SQL的面试题
- Oracle面试题库-PL/SQL
- Oracle面试题库-SQL
- SQL Server面试题