sql表记录值变成字段(转)

表中记录变字段:

表 a_a  :

student_id

student_name

subject

grade

20070001

mark

math 

88

20070001

mark

chinese

90

20070001

mark

english

95

20070002

green

math 

96

20070002

green

chinese

92

20070002

green

english

91

如何由上表a_a 得到下表a

student_id

student_name

math

chinese

english

20070001

mark

88

90

95

20070002

green

96

92

91

实现的sql语句:

select a.student_id,a.student_name,

(select grade from a_a where student_id=a.student_id and student_name=a.student_name and subject='math') as math,

(select grade from a_a where student_id=a.student_id and student_name=a.student_name and subject='chinese') as chinese,

(select grade from a_a where student_id=a.student_id and student_name=a.student_name and subject='english') as english

from (SELECT student_id,student_name  FROM a_agroup by student_id,student_name) a

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值