幾道常見的SQL面試題
點(diǎn)擊關(guān)注上方“SQL數(shù)據(jù)庫開發(fā)”,
設(shè)為“置頂或星標(biāo)”,第一時(shí)間送達(dá)干貨


你先按你自己的想法做一下,看結(jié)果有我的這個簡單嗎?
AccID :科目代碼,Occmonth :發(fā)生額月份,DebitOccur :發(fā)生額。
數(shù)據(jù)庫名:JcyAudit ,數(shù)據(jù)集: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)>802、
delete tablename
where 自動編號 not in(
select min( 自動編號)
from tablename
group by 學(xué)號,姓名,課程編號,課程名稱,分?jǐn)?shù))3、
select a.name, b.name
from team a, team b
where a.name < b.name4、
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.Debit101ccur5、
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 year6、
--SQL:
select * into b from a where 1<>1
--ORACLE:
create table b
As
Select * from a where 1=2注:<>(不等于)(SQL Server Compact)
比較兩個表達(dá)式。當(dāng)使用此運(yùn)算符比較非空表達(dá)式時(shí),如果左操作數(shù)不等于右操作數(shù),則結(jié)果為 TRUE。否則,結(jié)果為 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
) b9、
--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',開始時(shí)間,getdate())>511、
--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);
最后給大家分享我寫的SQL兩件套:《SQL基礎(chǔ)知識第二版》和《SQL高級知識第二版》的PDF電子版。里面有各個語法的解釋、大量的實(shí)例講解和批注等等,非常通俗易懂,方便大家跟著一起來實(shí)操。
有需要的讀者可以下載學(xué)習(xí),在下面的公眾號「數(shù)據(jù)前線」(非本號)后臺回復(fù)關(guān)鍵字:SQL,就行
數(shù)據(jù)前線
后臺回復(fù)關(guān)鍵字:1024,獲取一份精心整理的技術(shù)干貨
后臺回復(fù)關(guān)鍵字:進(jìn)群,帶你進(jìn)入高手如云的交流群
記得幫忙點(diǎn)「贊」和「在看」↓
謝謝啦
評論
圖片
表情

