收集了几道比较常见的SQL面试题,在不看底部参考答案的情况下,看自己能做对几道。
你先按你自己的想法做一下,看结果有我的这个简单吗?
AccID :科目代码,Occmonth :发生额月份,DebitOccur :发生额。
数据库名:JcyAudit ,数据集:Select * from TestDB
这道题的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);
零基础学 Python,来这里
只需7天时间,跨进Python编程大门,已有3800+加入
【基础】0基础入门python,24小时有人快速解答问题;
【提高】40多个项目实战,老手可以从真实场景中学习python;
【直播】不定期直播项目案例讲解,手把手教你如何分析项目;
【分享】优质python学习资料分享,让你在最短时间获得有价值的学习资源;圈友优质资料或学习分享,会不时给予赞赏支持,希望每个优质圈友既能赚回加入费用,也能快速成长,并享受分享与帮助他人的乐趣。
【人脉】收获一群志同道合的朋友,并且都是python从业者
【价格】本着布道思想,只需 69元 加入一个能保证学习效果的良心圈子。【赠予】后续圈主将开发python,0基础入门在线课程,免费送给圈友们,供巩固和系统化复习
(三重福利)最近入圈送大礼包:
1、2.7G、308份最新数据分析报告
2、40G 人工智能算法 视频课
3、Python爬虫课,共14课
更多精彩
在公众号后台对话框输入以下关键词
查看更多优质内容!
PM2.5 | 世界杯 | 惊喜 | 附书代码
觉得不错,请把这篇文章分享给你的朋友
转载 / 投稿请联系:data_circle_yoni
● 手把手 | 爬取京东评论,且修改网址直接可复用哦(送代码)