ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

sql面试题

2019-11-21 23:03:23  阅读:206  来源: 互联网

标签:面试题 aaa name SQL sql year where select


 

1.用一条SQL 语句 查询出每门课都大于80 分的学生姓名

 

2.  学生表 如下:

删除除了自动编号不同, 其他都相同的学生冗余信息 

 

 

3.一个叫 team 的表,里面只有一个字段name, 一共有4 条纪录,分别是a,b,c,d, 对应四个球对,现在四个球对进行比赛,用一条sql  语句显示所有可能的比赛组合.
你先按你自己的想法做一下,看结果有我的这个简单吗?

 

 

4.请用SQL  语句实现:从TestDB 数据表中查询出所有月份的发生额都比101 科目相应月份的发生额高的科目。请注意:TestDB 中有很多科目,都有1 -12 月份的发生额。
AccID :科目代码,Occmonth :发生额月份,DebitOccur :发生额。
数据库名:JcyAudit ,数据集:Select * from TestDB

 

 

5.面试题:怎么把这样一个表儿

查成这样一个结果

 

6. 说明:复制表( 只复制结构, 源表名:a新表名:b)

 

7.  说明:拷贝表( 拷贝数据, 源表名:a目标表名:b)

 

8. 说明:显示文章、提交人和最后回复时间

 

 

9. 说明:外连接查询( 表名1 :a表名2 :b)

 

10. 说明:日程安排提前五分钟提醒 

 

 

11. 说明:两张关联表,删除主表中已经在副表中没有的信息

 

12.有两个表A 和B ,均有key 和value 两个字段,如果B 的key 在A 中也有,就把B 的value 换为A 中对应的value
这道题的SQL 语句怎么写?

 

 

参考答案

1、

--方法一:
select distinct name 
from table 
where name not in (
select distinct name f
rom table where fenshu<=80
)
--方法二:
select name from table 
group by name 
having min(fenshu)>80

2、

delete tablename
where 自动编号 not in(
select min( 自动编号)
from tablename
group by 学号,姓名,课程编号,课程名称,分数)

3、

select a.name, b.name
from team a, team b 
where a.name < b.name

4、

select a.* from TestDB a,
(
select Occmonth,max(DebitOccur) Debit101ccur
from TestDB
where AccID='101' 
group by Occmonth) b
where a.Occmonth=b.Occmonth and a.DebitOccur>b.Debit101ccur

5、

select year,
(select amount from   aaa m where month=1   and m.year=aaa.year) as m1,
(select amount from   aaa m where month=2   and m.year=aaa.year) as m2,
(select amount from   aaa m where month=3   and m.year=aaa.year) as m3,
(select amount from   aaa m where month=4   and m.year=aaa.year) as m4
from aaa group by year

6、

--SQL:
select * into b from a where 1<>1

--ORACLE:
create table b
As
Select * from a where 1=2
 注:<>(不等于)(SQL Server Compact)

比较两个表达式。当使用此运算符比较非空表达式时,如果左操作数不等于右操作数,则结果为 TRUE。否则,结果为 FALSE。

7、

insert into b(a, b, c)
select d,e,f from a;

8、

select a.title,a.username,b.adddate
from table a,(
select max(adddate) adddate
from table where table.title=a.title
) b

9、

--SQL Server:
select a.a, a.b, a.c, b.c, b.d, b.f
from a LEFT OUTER JOIN b ON a.a = b.c

--ORACLE:
select a.a, a.b, a.c, b.c, b.d, b.f from a ,b
where a.a = b.c(+)

10、

--SQL Server
select * from 日程安排
where datediff('minute',开始时间,getdate())>5

11、

--SQL Server:
Delete from info
where not exists (
select * from infobz
where info.infid=infobz.infid
)

12、

update b set b.value=(
select a.value
from a where a.key=b.key)
where b.id in(
select b.id from b,a
where b.key=a.key);

 

——End——

 

     

    标签:面试题,aaa,name,SQL,sql,year,where,select
    来源: https://www.cnblogs.com/lianhaifeng/p/11908994.html

    本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
    2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
    3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
    4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
    5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

    专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

    Copyright (C)ICode9.com, All Rights Reserved.

    ICode9版权所有