小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Sql常見面試題

 韻朵之家 2009-04-13

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

name   kecheng   fenshu
張三     語文       81
張三     數(shù)學       75
李四     語文       76
李四     數(shù)學       90
王五     語文       81
王五     數(shù)學       100
王五     英語       90

A: select distinct name from table where name not in (select distinct name from table where fenshu<=80)
select name from table group by name having min(fenshu)>80


2.
學生表 如下:
自動編號   學號   姓名 課程編號 課程名稱 分數(shù)
1        2005001
張三 0001      數(shù)學    69
2        2005002
李四 0001      數(shù)學    89
3        2005001
張三 0001      數(shù)學    69
刪除除了自動編號不同,其他都相同的學生冗余信息

A: delete tablename where
自動編號 not in(select min(自動編號) from tablename group by 學號,姓名,課程編號,課程名稱,分數(shù))

3.一個叫department的表,里面只有一個字段name,一共有4條紀錄,分別是a,b,c,d,對應四個球?qū)ΓF(xiàn)在四個球?qū)M行比賽,用一條sql語句顯示所有可能的比賽組合.
你先按你自己的想法做一下,看結(jié)果有我的這個簡單嗎?

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

4.請用SQL語句實現(xiàn):從TestDB數(shù)據(jù)表中查詢出所有月份的發(fā)生額都比101科目相應月份的發(fā)生額高的科目。請注意:TestDB中有很多科目,都有112月份的發(fā)生額。
AccID
:科目代碼,Occmonth:發(fā)生額月份,DebitOccur:發(fā)生額。
數(shù)據(jù)庫名:JcyAudit,數(shù)據(jù)集: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.面試題:怎么把這樣一個表兒
year   month amount
1991   1     1.1
1991   2     1.2
1991   3     1.3
1991   4     1.4
1992   1     2.1
1992   2     2.2
1992   3     2.3
1992   4     2.4
查成這樣一個結(jié)果
year m1   m2   m3   m4
1991 1.1 1.2 1.3 1.4
1992 2.1 2.2 2.3 2.4

答案一、
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.
說明:復制表(只復制結(jié)構(gòu),源表名:a 新表名:b)

SQL: select * into b from a where 1<>1
ORACLE:create table b

As

Select * from a where 1=2
7.
說明:拷貝表(拷貝數(shù)據(jù),源表名:a 目標表名:b)

SQL: insert into b(a, b, c) select d,e,f from a;

8.
說明:顯示文章、提交人和最后回復時間
SQL: select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b

9.
說明:外連接查詢(表名1a 表名2b)

SQL: select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUTER JOIN b ON a.a = b.c

ORACLEselect a.a, a.b, a.c, b.c, b.d, b.f from a ,b

where a.a = b.c(+)

10.
說明:日程安排提前五分鐘提醒
SQL: select * from
日程安排 where datediff('minute',f開始時間,getdate())>5

11.
說明:兩張關(guān)聯(lián)表,刪除主表中已經(jīng)在副表中沒有的信息

SQL:
Delete from info where not exists (select * from infobz where info.infid=infobz.infid )

*******************************************************************************

12.有兩個表AB,均有keyvalue兩個字段,如果BkeyA中也有,就把Bvalue換為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);

***************************************************************************

13.高級sql面試題

原表:
courseid coursename score
-------------------------------------
1 java 70
2 oracle 90
3 xml 40
4 jsp 30
5 servlet 80
-------------------------------------
為了便于閱讀,查詢此表后的結(jié)果顯式如下(及格分數(shù)為60):
courseid coursename score mark
---------------------------------------------------
1 java 70 pass
2 oracle 90 pass
3 xml 40 fail
4 jsp 30 fail
5 servlet 80 pass
---------------------------------------------------
寫出此查詢語句


select courseid, coursename ,score ,decodesign(score-60),-1,'fail','pass') as mark from course

完全正確

SQL> desc course_v
Name Null? Type
----------------------------------------- -------- ----------------------------
COURSEID NUMBER
COURSENAME VARCHAR2(10)
SCORE NUMBER

SQL> select * from course_v;

COURSEID COURSENAME SCORE
---------- ---------- ----------
1 java 70
2 oracle 90
3 xml 40
4 jsp 30
5 servlet 80

SQL> select courseid, coursename ,score ,decode(sign(score-60),-1,'fail','pass') as mark from course_v;

COURSEID COURSENAME SCORE MARK
---------- ---------- ---------- ----
1 java 70 pass
2 oracle 90 pass
3 xml 40 fail
4 jsp 30 fail
5 servlet 80 pass

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多