Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.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 - Fatal编程技术网

Mysql 学校作业交付清单

Mysql 学校作业交付清单,mysql,Mysql,我有两张桌子: 表学生和完成的作业表 Students table +--------------------------+---------------------------------+ | id | name | +--------------------------+---------------------------------+ | 1

我有两张桌子: 表学生和完成的作业表

Students table
+--------------------------+---------------------------------+
| id                       |   name                          |
+--------------------------+---------------------------------+
| 1                        |   ADAM                          |
| 2                        |   BRIGITTE                      |
| 3                        |   ANNE                          |
+--------------------------+---------------------------------+

table student works
+---------------+-------------------------+------------------+
| id_works      |   works                 |   id_student     |
+---------------+-------------------------+------------------+
| 1             |   airplane wing         |   1              |
| 2             |   volcano               |   2              |
| 3             |   law of gravity        |   1              |
| 4             |   airplane wing         |   3              |
| 5             |   law of gravity        |   1              |
+-----------------------------------------+------------------+
如何为返回整个学生列表的作业进行选择,以指示作业已交付?(重要:所有学生的名单)

范例

LIST FOR WORK **airplane wing**
+--------------------------+---------------------------------+
|  ADAM                    |   X                             |
|  BRIGITTE                |                                 |
|  ANNE                    |   X                             |
+--------------------------+--------------------- -----------+
我用LEF-JOIN和IF试过,但不是所有学生的名单都没有重复

SELECT
    s.name ,
    w.work,
    w.resid_id,
    if(w.work  = 'airplane wing', 'X', '') as mark

    FROM  students s
    LEFT JOIN works w
    ON  s.id = w.id_student

    ORDER BY s.name ASC

这会给你一份所有学生的名单 对于那些没有完成工作的人来说,
id\u works
works
字段将为空

SELECT s.name, w.id_works, w.works

FROM  students s
LEFT JOIN works w
    ON (w.id_student = s.id AND w.works = 'airplane wing')

ORDER BY s.name ASC