提前谢谢你,我好像不明白!
我有两张桌子
类别
身份证名称
1能力
2英语
作记号
用户标识类别标识
1 1 25个
1 2 45个
2 1 34个
3 2 45个
4 1 56个
4 2 66个
我希望输出的是一个mysql查询
输出
用户ID智能标记英文标记
1 25 45个
45666个
由于我是mysql新手,我只能得到一个类别或另一个类别,我不能把它们放在同一行。此外,当用户有两个类别标记时,我们应该考虑。
最佳答案
如果CASE
(s)的数目是固定的,我们可以使用GROUP BY
表达式和category
子句通过以下查询来实现这一点。
查询
select * from
(
select UserId,
max(case when CategoryId = 1 then Mark else null end) as AptitudeMark,
max(case when CategoryId = 2 then Mark else null end) as EnglishMark
from Mark
group by UserId
)t
where t.AptitudeMark is not null
and t.EnglishMark is not null;
关于mysql - 合并多个子行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32884363/