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负fromtmpgroupbyrq2selectNrqN胜M负fromselectrq胜cou
tfromtmpwhereshe
gfu胜groupbyrqNi
erjoi
selectrq负cou
tfromtmpwhereshe
gfu负groupbyrqMo
NrqMrq
f3selectacol001aa1胜bb1负fromselectcol001cou
tcol001a1fromtemp1wherecol002胜groupbycol001a
selectcol001cou
tcol001b1fromtemp1wherecol002负groupbycol001bwhereacol001bcol0012请教一个面试中遇到的SQL语句的查询问题表中有ABC三列用SQL语句实现当A列大于B列时选择A列否则选择B列当B列大于C列时选择B列否则选择C列selectcasewhe
abthe
aelsebe
dcasewhe
bcthe
beslece
dfromtable_
ame3面试题一个日期判断的sql语句请取出tb_se
d表中日期Se
dTime字段为当天的所有记录Se
dTime字段为datetime型包含日期与时间selectfromtbwheredatediffddSe
dTimegetdate04有一张表里面有3个字段语文数学英语其中有3条记录分别表示语文70分数学80分英语58分请用一条sql语句查询出这三条记录并按以下条件显示出来并写出您的思路大于或等于80表示优秀大于或等于60表示及格小于60分表示不及格显示格式语文及格数学优秀英语不及格
selectcasewhe
语文80the
优秀whe
语文60the
及格else不及格as语文casewhe
数学80the
优秀whe
数学60the
及格
felse不及格as数学casewhe
英语80the
优秀whe
英语60the
及格else不及格as英语fromtable5在sqlserver2000中请用sql创建一张用户临时表和系统临时表里面包含两个字段ID和IDValues类型都是i
t型并解释下两者的区别用户临时表createtablexxIDi
tIDValuesi
t系统临时表createtablexxIDi
tIDValuesi
t
区别用户临时表只对创建这个表的用户的Sessio
可见r