Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在MYSQL中从同一个表提取的视图上添加列_Mysql_Pivot - Fatal编程技术网

如何在MYSQL中从同一个表提取的视图上添加列

如何在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

我有这些桌子:

出席人数\u tbl

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;

考虑应用程序代码中的数据显示问题