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

分享

數(shù)據(jù)庫(kù)題目

 zhulin3141 2010-08-25

SQL經(jīng)典面試題及答案

1.一道SQL語(yǔ)句面試題,關(guān)于group by
表內(nèi)容:
2005-05-09 勝
2005-05-09 勝
2005-05-09 負(fù)
2005-05-09 負(fù)
2005-05-10 勝
2005-05-10 負(fù)
2005-05-10 負(fù)

如果要生成下列結(jié)果, 該如何寫(xiě)sql語(yǔ)句?

勝 負(fù)
2005-05-09 2 2
2005-05-10 1 2
------------------------------------------
create table #tmp(rq varchar(10),shengfu nchar(1))

insert into #tmp values('2005-05-09','勝')
insert into #tmp values('2005-05-09','勝')
insert into #tmp values('2005-05-09','負(fù)')
insert into #tmp values('2005-05-09','負(fù)')
insert into #tmp values('2005-05-10','勝')
insert into #tmp values('2005-05-10','負(fù)')
insert into #tmp values('2005-05-10','負(fù)')
1)select rq, sum(case when shengfu='勝' then 1 else 0 end)'勝',sum(case when shengfu='負(fù)' then 1 else 0 end)'負(fù)' from #tmp group by rq
2) select N.rq,N.勝,M.負(fù) from (
select rq,勝=count(*) from #tmp where shengfu='勝'group by rq)N inner join
(select rq,負(fù)=count(*) from #tmp where shengfu='負(fù)'group by rq)M on N.rq=M.rq
3)select a.col001,a.a1 勝,b.b1 負(fù) from
(select col001,count(col001) a1 from temp1 where col002='勝' group by col001) a,
(select col001,count(col001) b1 from temp1 where col002='負(fù)' group by col001) b
where a.col001=b.col001
2.請(qǐng)教一個(gè)面試中遇到的SQL語(yǔ)句的查詢問(wèn)題
表中有A B C三列,用SQL語(yǔ)句實(shí)現(xiàn):當(dāng)A列大于B列時(shí)選擇A列否則選擇B列,當(dāng)B列大于C列時(shí)選擇B列否則選擇C列。
------------------------------------------
select (case when a>b then a else b end ),
(case when b>c then b esle c end)
from table_name
3.面試題:一個(gè)日期判斷的sql語(yǔ)句?
請(qǐng)取出tb_send表中日期(SendTime字段)為當(dāng)天的所有記錄?(SendTime字段為datetime型,包含日期與時(shí)間)
------------------------------------------
select * from tb where datediff(dd,SendTime,getdate())=0
4.有一張表,里面有3個(gè)字段:語(yǔ)文,數(shù)學(xué),英語(yǔ)。其中有3條記錄分別表示語(yǔ)文70分,數(shù)學(xué)80分,英語(yǔ)58分,請(qǐng)用一條sql語(yǔ)句查詢出這三條記錄并按以下條件顯示出來(lái)(并寫(xiě)出您的思路):
大于或等于80表示優(yōu)秀,大于或等于60表示及格,小于60分表示不及格。
顯示格式:
語(yǔ)文數(shù)學(xué)英語(yǔ)
及格優(yōu)秀不及格
------------------------------------------
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 table
5.在sqlserver2000中請(qǐng)用sql創(chuàng)建一張用戶臨時(shí)表和系統(tǒng)臨時(shí)表,里面包含兩個(gè)字段ID和IDValues,類(lèi)型都是int型,并解釋下兩者的區(qū)別?
------------------------------------------
用戶臨時(shí)表:create table #xx(ID int, IDValues int)
系統(tǒng)臨時(shí)表:create table ##xx(ID int, IDValues int)

區(qū)別:
用戶臨時(shí)表只對(duì)創(chuàng)建這個(gè)表的用戶的Session可見(jiàn),對(duì)其他進(jìn)程是不可見(jiàn)的.
當(dāng)創(chuàng)建它的進(jìn)程消失時(shí)這個(gè)臨時(shí)表就自動(dòng)刪除.

全局臨時(shí)表對(duì)整個(gè)SQL Server實(shí)例都可見(jiàn),但是所有訪問(wèn)它的Session都消失的時(shí)候,它也自動(dòng)刪除.
6.sqlserver2000是一種大型數(shù)據(jù)庫(kù),他的存儲(chǔ)容量只受存儲(chǔ)介質(zhì)的限制,請(qǐng)問(wèn)它是通過(guò)什么方式實(shí)現(xiàn)這種無(wú)限容量機(jī)制的。
------------------------------------------
它的所有數(shù)據(jù)都存儲(chǔ)在數(shù)據(jù)文件中(*.dbf),所以只要文件夠大,SQLServer的存儲(chǔ)容量是可以擴(kuò)大的.
SQL Server 2000 數(shù)據(jù)庫(kù)有三種類(lèi)型的文件:

主要數(shù)據(jù)文件
主要數(shù)據(jù)文件是數(shù)據(jù)庫(kù)的起點(diǎn),指向數(shù)據(jù)庫(kù)中文件的其它部分。每個(gè)數(shù)據(jù)庫(kù)都有一個(gè)主要數(shù)據(jù)文件。主要數(shù)據(jù)文件的推薦文件擴(kuò)展名是 .mdf。

次要數(shù)據(jù)文件
次要數(shù)據(jù)文件包含除主要數(shù)據(jù)文件外的所有數(shù)據(jù)文件。有些數(shù)據(jù)庫(kù)可能沒(méi)有次要數(shù)據(jù)文件,而有些數(shù)據(jù)庫(kù)則有多個(gè)次要數(shù)據(jù)文件。次要數(shù)據(jù)文件的推薦文件擴(kuò)展名是 .ndf。

日志文件
日志文件包含恢復(fù)數(shù)據(jù)庫(kù)所需的所有日志信息。每個(gè)數(shù)據(jù)庫(kù)必須至少有一個(gè)日志文件,但可以不止一個(gè)。日志文件的推薦文件擴(kuò)展名是 .ldf。
7.請(qǐng)用一個(gè)sql語(yǔ)句得出結(jié)果
從table1,table2中取出如table3所列格式數(shù)據(jù),注意提供的數(shù)據(jù)及結(jié)果不準(zhǔn)確,只是作為一個(gè)格式向大家請(qǐng)教。
如使用存儲(chǔ)過(guò)程也可以。

table1

月份mon 部門(mén)dep 業(yè)績(jī)yj
-------------------------------
一月份0110
一月份0210
一月份035
二月份028
二月份049
三月份038

table2

部門(mén)dep部門(mén)名稱(chēng)dname
--------------------------------
01國(guó)內(nèi)業(yè)務(wù)一部
02國(guó)內(nèi)業(yè)務(wù)二部
03國(guó)內(nèi)業(yè)務(wù)三部
04國(guó)際業(yè)務(wù)部

table3 (result)

部門(mén)dep 一月份二月份三月份
--------------------------------------
0110nullnull
02108null
03null58
04nullnull9
------------------------------------------
1)
select a.部門(mén)名稱(chēng)dname,b.業(yè)績(jī)yj as '一月份',c.業(yè)績(jī)yj as '二月份',d.業(yè)績(jī)yj as '三月份'
from table1 a,table2 b,table2 c,table2 d
where a.部門(mén)dep = b.部門(mén)dep and b.月份mon = '一月份' and
a.部門(mén)dep = c.部門(mén)dep and c.月份mon = '二月份' and
a.部門(mén)dep = d.部門(mén)dep and d.月份mon = '三月份' and
2)
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.dep
8.華為一道面試題
一個(gè)表中的Id有多個(gè)記錄,把所有這個(gè)id的記錄查出來(lái),并顯示共有多少條記錄數(shù)。
------------------------------------------
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>1

 

本文來(lái)自CSDN博客,轉(zhuǎn)載請(qǐng)標(biāo)明出處:http://blog.csdn.net/zhan198271/archive/2008/12/25/3599225.aspx

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

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類(lèi)似文章 更多