请问怎么从A表查出B表?

请问怎么从A表查出B表?
A表:
name   subject    score
张三     语文        80
张三     数学        92
张三     英语        95
李四     语文        78
李四     数学        85
李四     英语        93
B表:
name    语文    数学    英语
张三      80       92       95
李四      78       85       93

#笔试题目#
全部评论
sqlserver 中可以使用pivot实现 mysql 不支持该语法 
点赞 回复
分享
发布于 2018-07-09 14:33
where B.?=?
点赞 回复
分享
发布于 2018-07-09 13:52
联想
校招火热招聘中
官网直投
你这个是纵表转成横表。。。。什么查出。。
点赞 回复
分享
发布于 2018-07-09 14:32
mysql的话可以这样写,性能差勿喷: select t1.name,t1.score as 语文,t2.score as 数学,t3.score as 英语 from (select A.name,A.score from A where A.subject = '语文') as t1,  (select A.name,A.score from A where A.subject = '数学') as t2, (select A.name,A.score from A where A.subject = '英语') as t3 where t1.name = t2.name and t1.name = t3.name;
点赞 回复
分享
发布于 2018-07-10 10:05
行转列 和列转行都可以实现,找个博客看下
点赞 回复
分享
发布于 2018-07-10 12:08
select name, max(case subject when '语文' then score else 0 end) 语文, max(case subject when '数学' then score else 0 end) 数学, max(case subject when '英语' then score else 0 end) 英语 from a group by name;  mysql 列传行,我已经找到答案了,谢谢大家。
点赞 回复
分享
发布于 2018-07-18 19:02

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务