SQL经典面试题及答案
1一道SQL语句面试题,关于groupby表内容:20050509胜20050509胜20050509负20050509负20050510胜20050510负20050510负
如果要生成下列结果该如何写sql语句
胜负20050509222005051012createtabletmprqvarchar10she
gfu
char1
i
serti
totmpvalues20050509胜i
serti
totmpvalues20050509胜i
serti
totmpvalues20050509负i
serti
totmpvalues20050509负i
serti
totmpvalues20050510胜i
serti
totmpvalues20050510负i
serti
totmpvalues20050510负
1selectrqsumcasewhe
she
gfu胜the
1else0e
d胜sumcasewhe
she
gfu负the
1else0e
d负fromtmpgroupbyrq2selectNrqNMfromselectrqcou
tfromtmpwhereshe
gfu胜groupbyrqNi
erjoi
selectrqcou
tfromtmpwhereshe
gfu负groupbyrqMo
NrqMrq3selectacol001aa1胜bb1负fromselectcol001cou
tcol001a1fromtemp1wherecol002胜groupbycol001aselectcol001cou
tcol001b1fromtemp1wherecol002负groupbycol001bwhereacol001bcol001
2请教一个面试中遇到的SQL语句的查询问题
f表中有ABC三列用SQL语句实现:当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列。selectcasewhe
abthe
aelsebe
dcasewhe
bcthe
beslece
dfromtable_
ame
3面试题:一个日期判断的sql语句?请取出tb_se
d表中日期Se
dTime字段为当天的所有记录Se
dTime字段为datetime型,包含日期与时间selectfromtbwheredatediffddSe
dTimegetdate0
4有一张表,里面有3个字段:语文,数学,英语。其中有3条记录分别表示语
文70分,数学80分,英语58分,请用一条sql语句查询出这三条记录并按以
下条件显示出来(并写出您的思路):
大于或等于80表示优秀,大于或等于60表示及格,小于60分表示不及
格。
显示格式:
语文
数
学
英语
及格
优
秀
不及格
select
casewhe
语文80the
优秀
whe
语文60the
及格
else不及格as语文
casewhe
数学80the
优秀
whe
数学60the
及格
else不及格as数学
casewhe
英语80the
优秀
whe
英语60the
及格
else不及格as英语
fromtable
5在sqlserver2000中请用sql创建一张用户临时表和系统临时表,里面包含两个字段ID和IDValues类型都是i
t型,并解释下两者的区别用户临时表createtablexxIDi
tIDValuesi
t系统临时表createtablexxIDi
tIDValuesi
r