如何在MYSQL中从同一个表提取的视图上添加列
我有这些桌子: 出席人数\u tbl如何在MYSQL中从同一个表提取的视图上添加列,mysql,pivot,Mysql,Pivot,我有这些桌子: 出席人数\u tbl id | date | ----------------------- 1 | 2020-03-15 | 2 | 2020-03-16 | id | attendance_id | name | remark | --------------------------------------------- 1 | 1 | oliver | P
id | date |
-----------------------
1 | 2020-03-15 |
2 | 2020-03-16 |
id | attendance_id | name | remark |
---------------------------------------------
1 | 1 | oliver | P |
2 | 1 | john | P |
3 | 2 | oliver | P |
4 | 2 | john | L |
学生
id | date |
-----------------------
1 | 2020-03-15 |
2 | 2020-03-16 |
id | attendance_id | name | remark |
---------------------------------------------
1 | 1 | oliver | P |
2 | 1 | john | P |
3 | 2 | oliver | P |
4 | 2 | john | L |
考勤\u id
与考勤无关\u tbl
我想实现这样的目标:
name | 2020-03-15 | 2020-03-16 |
--------------------------------------
oliver | P | P |
john | P | L |
我得到了两个日期(开始和开始)之间的所有结果,因此如果在用户给定的范围内有更多的日期,那么这些列可能会相加
但是我很难解决这个问题。这是解决上述问题的方法之一
select names,
Max(case when attendence_date='2020-03-15' then remark else null end) as '2015-03-15',
max(case when attendence_date='2020-03-16' then remark else null end )as '2015-03-16'
from attendence a
join student_attendence b
on a.id=b.attendence_id
group by names;
考虑应用程序代码中的数据显示问题