June 22, 2018
Mysql: 一对多查询, 将多条记录合并成一条记录, mysql两表联合查询,一对多
t_user表如下
cj表如下:
要获得的查询结果:
解决办法:
方法一:
select cjc.uid,u.uname,cjc.数学,cjc.英语,cjc.语文,u.type from
(select uid,max(case subj when '数学' then score else 0 end) 数学,
max(case subj when '语文' then score else 0 end) 语文,
max(case subj when '英语' then score else 0 end) 英语
from cj
group by uid) cjc
left jo… Read More