首页 > 应用开发 > Java > 大厂面试常见的几道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 学号,姓名,课程编号,课程名称,分数)
select a.name, b.name from team a, team b where a.name < b.name
select a.* from TestDB a,(select Occmonth,max(DebitOccur) Debit101ccurfrom TestDBwhere 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 bAsSelect * from a where 1=2
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 Serverselect * from 日程安排
where datediff('minute',开始时间,getdate())>5--SQL Server:Delete from info where not exists (select * from infobz where info.infid=infobz.infid)
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);
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31548651/viewspace-2776097/ ,如需转载,请注明出处,否则将追究法律责任。