sql a 表 若包含b表 则a 表 列显示_几道常见的SQL面试题,看你能答对几道?
分享幾道比較常見(jiàn)的SQL面試題,在不看底部參考答案的情況下,看自己能做對(duì)幾道。
1.用一條SQL 語(yǔ)句 查詢出每門課都大于80 分的學(xué)生姓名
2. 學(xué)生表 如下:
刪除除了自動(dòng)編號(hào)不同, 其他都相同的學(xué)生冗余信息
3.一個(gè)叫 team 的表,里面只有一個(gè)字段name, 一共有4 條紀(jì)錄,分別是a,b,c,d, 對(duì)應(yīng)四個(gè)球?qū)?#xff0c;現(xiàn)在四個(gè)球?qū)M(jìn)行比賽,用一條sql 語(yǔ)句顯示所有可能的比賽組合.
你先按你自己的想法做一下,看結(jié)果有我的這個(gè)簡(jiǎn)單嗎?
4.請(qǐng)用SQL 語(yǔ)句實(shí)現(xiàn):從TestDB 數(shù)據(jù)表中查詢出所有月份的發(fā)生額都比101 科目相應(yīng)月份的發(fā)生額高的科目。請(qǐng)注意:TestDB 中有很多科目,都有1 -12 月份的發(fā)生額。
AccID :科目代碼,Occmonth :發(fā)生額月份,DebitOccur :發(fā)生額。
數(shù)據(jù)庫(kù)名:JcyAudit ,數(shù)據(jù)集:Select * from TestDB
5.面試題:怎么把這樣一個(gè)表
查成這樣一個(gè)結(jié)果
6. 說(shuō)明:復(fù)制表( 只復(fù)制結(jié)構(gòu), 源表名:a新表名:b)
7. 說(shuō)明:拷貝表( 拷貝數(shù)據(jù), 源表名:a目標(biāo)表名:b)
8. 說(shuō)明:顯示文章、提交人和最后回復(fù)時(shí)間
9. 說(shuō)明:外連接查詢( 表名1 :a表名2 :b)
10. 說(shuō)明:日程安排提前五分鐘提醒
11. 說(shuō)明:兩張關(guān)聯(lián)表,刪除主表中已經(jīng)在副表中沒(méi)有的信息
12.有兩個(gè)表A 和B ,均有key 和value 兩個(gè)字段,如果B 的key 在A 中也有,就把B 的value 換為A 中對(duì)應(yīng)的value
這道題的SQL 語(yǔ)句怎么寫?
13.表tab內(nèi)容:
如果要生成下列結(jié)果, 該如何寫sql語(yǔ)句?
14.表中有A B C三列,用SQL語(yǔ)句實(shí)現(xiàn):當(dāng)A列大于B列時(shí)選擇A列否則選擇B列,當(dāng)B列大于C列時(shí)選擇B列否則選擇C列。
15.請(qǐng)取出tb_send表中日期(SendTime字段)為當(dāng)天的所有記錄?
(SendTime字段為datetime型,包含日期與時(shí)間)
16.有一張表table,里面有3個(gè)字段:語(yǔ)文,數(shù)學(xué),英語(yǔ)。其中有3條記錄
請(qǐng)用一條sql語(yǔ)句查詢出這三條記錄并按以下條件顯示出來(lái)(并寫出您的思路): 大于或等于80表示優(yōu)秀,大于或等于60表示及格,小于60分表示不及格。 顯示格式:
17.從table1,table2中取出如table3所列格式數(shù)據(jù),其中table1只展示了部分?jǐn)?shù)據(jù),還有4到12月份的數(shù)據(jù)未完全展示,table3也只展示了部分?jǐn)?shù)據(jù),還有4到12月份的數(shù)據(jù)列未完全展示。
table1
table2
結(jié)果如下:
table3
18.一個(gè)表中的Id有多個(gè)記錄,把所有這個(gè)id的記錄查出來(lái),并顯示共有多少條記錄數(shù)。
19.表形式如下:
想得到如下形式的查詢結(jié)果
sql語(yǔ)句怎么寫?
參考答案
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 自動(dòng)編號(hào) not in( select min( 自動(dòng)編號(hào)) from tablename group by 學(xué)號(hào),姓名,課程編號(hào),課程名稱,分?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)
比較兩個(gè)表達(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',開(kāi)始時(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);13
create table tmp(Tdate varchar(10),Tresulte nchar(1));insert into tmp values('2019-05-09','勝'); insert into tmp values('2019-05-09','勝'); insert into tmp values('2019-05-09','負(fù)'); insert into tmp values('2019-05-09','負(fù)'); insert into tmp values('2019-05-10','勝'); insert into tmp values('2019-05-10','負(fù)'); insert into tmp values('2019-05-10','負(fù)');--方法一 select Tdate '日期', sum(case when Tresulte ='勝' then 1 else 0 end)'勝', sum(case when Tresulte ='負(fù)' then 1 else 0 end)'負(fù)' from tmp group by Tdate ; --方法二 select N.Tdate '日期',N.勝,M.負(fù) from ( select Tdate ,count(*) '勝' from tmp where Tresulte ='勝' group by Tdate ) N inner join ( select Tdate ,count(*) '負(fù)' from tmp where Tresulte ='負(fù)' group by Tdate ) M on N.Tdate =M.Tdate ;14
select (case when a>b then a else b end ), (case when b>c then b esle c end) from table_name15
select * from tb where datediff(dd,SendTime,getdate())=016
select (case when 語(yǔ)文>=80 then '優(yōu)秀'when 語(yǔ)文>=60 then '及格'else '不及格') as 語(yǔ)文, (case when 數(shù)學(xué)>=80 then '優(yōu)秀'when 數(shù)學(xué)>=60 then '及格'else '不及格') as 數(shù)學(xué), (case when 英語(yǔ)>=80 then '優(yōu)秀'when 英語(yǔ)>=60 then '及格'else '不及格') as 英語(yǔ), from table17
select a.dep, sum(case when b.mon=1 then b.yj else 0 end) as '一月份', sum(case when b.mon=2 then b.yj else 0 end) as '二月份', sum(case when b.mon=3 then b.yj else 0 end) as '三月份', sum(case when b.mon=4 then b.yj else 0 end) as '四月份', sum(case when b.mon=5 then b.yj else 0 end) as '五月份', sum(case when b.mon=6 then b.yj else 0 end) as '六月份', sum(case when b.mon=7 then b.yj else 0 end) as '七月份', sum(case when b.mon=8 then b.yj else 0 end) as '八月份', sum(case when b.mon=9 then b.yj else 0 end) as '九月份', sum(case when b.mon=10 then b.yj else 0 end) as '十月份', sum(case when b.mon=11 then b.yj else 0 end) as '十一月份', sum(case when b.mon=12 then b.yj else 0 end) as '十二月份', from table2 a left join table1 b on a.dep=b.dep18
--方法一 select id,Count(*) from tb group by id having count(*)>1; --方法二 select * from (select count(ID) as count from table group by ID)T where T.count>119
--連接查詢 SELECT b.YEAR, SUM(a.salary) salary FROM hello a, hello b WHERE a.YEAR <= b.YEAR GROUP BY b.YEAR--子查詢 select year , (select sum(salary) from hello as B where B.year<=A.year ) from hello as A覺(jué)得不錯(cuò),記得幫忙點(diǎn)個(gè)贊,謝謝啦~
總結(jié)
以上是生活随笔為你收集整理的sql a 表 若包含b表 则a 表 列显示_几道常见的SQL面试题,看你能答对几道?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 怎么串联两个路由器两个路由器如何连接成一
- 下一篇: ros自己写避障算法_迷雾学术篇|视觉感