遇到的一个sql的面试题

表结构

表名:stu

将stu 改为 如下显示方式

 

方法1:

select table1.studentname,table1.语文,table2.数学,table3.英语 from ( select studentname, isnull(score,0) as '语文'  from stu where objname='语文') as table1
inner join (select studentname, isnull(score,0) as '数学'  from stu where objname='数学' )as table2 on table2.studentname=table1.studentname
inner join (select studentname, isnull(score,0) as '英语'  from stu where objname='英语' )as table3 on table3.studentname=table1.studentname


方法2:

select A.studentname,isnull(A.score,0) as 语文,isnull(B.score,0) as 数学,isnull(C.score,0) as 英语
from  stu A,stu B,stu C
where A.studentname=B.studentname and B.studentname=C.studentname
and A.objname='语文' and B.objname='数学' and C.objname='英语'


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值