日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

大厂面试常见的几道SQL题,看你能答吗?

發布時間:2024/9/30 数据库 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 大厂面试常见的几道SQL题,看你能答吗? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

收集了幾道比較常見的SQL面試題,在不看底部參考答案的情況下,看自己能做對幾道。

1.用一條SQL語句查詢出每門課都大于80分的學生姓名


答案:

--方法一: 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.一個叫team的表,里面只有一個字段name, 一共有4條紀錄,分別是a,b,c,d, 對應四個球對,現在四個球對進行比賽,用一條sql語句顯示所有可能的比賽組合。

你先按你自己的想法做一下,看結果有我的這個簡單嗎?

答案:

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

4.請用SQL句實現:

從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

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.說明:復制表( 只復制結構, 源表名:a新表名:b)

答案:

--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. 說明:拷貝表( 拷貝數據, 源表名:a目標表名:b)

答案:

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. 說明:外連接查詢( 表名1 :a表名2 :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(+)

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.有兩個表A 和B ,均有key 和value 兩個字段,如果B 的key 在A 中也有,就把B 的value 換為A 中對應的value。

這道題的SQL語句怎么寫?

答案:

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题,看你能答吗?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。