收集了几道比较常见的SQL面试题,在不看底部参考答案的情况下,看自己能做对几道。
--方法一:
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
delete tablename
where 自动编号 not in(
select min( 自动编号)
from tablename
group by 学号,姓名,课程编号,课程名称,分数)
team
的表,里面只有一个字段name
, 一共有4 条纪录,分别是a,b,c,d
, 对应四个球对,现在四个球对进行比赛,用一条sql 语句显示所有可能的比赛组合.select a.name, b.name
from team a, team b
where a.name < b.name
TestDB
数据表中查询出所有月份的发生额都比101 科目相应月份的发生额高的科目。请注意:TestDB
中有很多科目,都有1 -12 月份的发生额。AccID
:科目代码,Occmonth
:发生额月份,DebitOccur
:发生额。JcyAudit
,数据集:Select * from TestDB
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
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
--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
。
a
目标表名:b
)insert into b(a, b, c)
select d,e,f from a;
select a.title,a.username,b.adddate
from table a,(
select max(adddate) adddate
from table where table.title=a.title
) b
--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(+)
--SQL Server
select * from 日程安排
where datediff('minute',开始时间,getdate())>5
--SQL Server:
Delete from info
where not exists (
select * from infobz
where info.infid=infobz.infid
)
key
和value
两个字段,如果B 的key
在A 中也有,就把B 的value
换为A 中对应的value
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);