我想组合两个或多个具有相同名称的行,并将它们的值放在两个单独的列中。使用以下图像可以更清楚地解决问题:
我的预期输出是:
您可以在此处查看小提琴:fiddle
到目前为止我尝试过的是MySQL代码:
Select subjects, mark_score, activity
FROM(
SELECT subjects, mark_score,
(SELECT regd, subjects, mark_score
FROM exo_i WHERE entry='7' and regd='19') as activity
FROM exo_i WHERE regd='19' GROUP BY subjects)t
答案 0 :(得分:1)
正如评论中所讨论的,要求是显示"标记"对于" FA1"进入和"活动"对于" SA1"活动。假设不能有多个具有这些值的行(即regd
,subjectsa
和activity
的组合是唯一的),您可以为每个活动创建一个子查询,并加入他们:
SELECT a.regd, a.subjects, a.marks, b.activity
FROM (SELECT regd, subjects, marks
FROM mytable
WHERE entry = 'FA1') a
JOIN (SELECT regd, subjects, marks AS activity
FROM mytable
WHERE entry = 'SA1') b ON a.regd = b.regd AND a.subjects = b.subjects