我有一个问题,我的朋友说我必须使用表映射...但是我不知道什么是表映射,也不知道我要做什么,是否正确

我有这张桌子:员工

+-------+------------+------+-------------------------+
| ac_no | department | rank | email                   |
+-------+------------+------+-------------------------+
| 12ac  |  01        | 08   | [email protected]             |
| 1an4  |  02        | 08   | [email protected]             |
| dr17  |  01        | 08   | [email protected]             |
| 13IN  |  01        | 05   | [email protected]           |
| TE12  |  02        | 05   | [email protected]            |
| GR45  |  01        | 05   | [email protected]          |
+-------+------------+------+-------------------------+


我必须从表employee的数据插入表映射

目标是获取所有排名为08的数据

+-------+------------+------+-------------------------+
| 12ac  |  01        | 08   | [email protected]             |
| 1an4  |  02        | 08   | [email protected]             |
| dr17  |  01        | 08   | [email protected]             |
+-------+------------+------+-------------------------+


并查找在同一部门中排名为05的数据,然后获取电子邮件。

+-------+---------------+------------+------------------------------+
| ac_no |email          | department |               email          |
+-------+---------------+------------+------------------------------+
| 12ac  | [email protected]   |   01       | [email protected];[email protected] |
| 1an4  | [email protected]   |   02       | [email protected]                 |
| dr17  | [email protected]   |   01       | [email protected];[email protected] |
+-------+---------------+------------+------------------------------+


我想使用过程将数据从表employee转换为表映射,但是我不知道该如何获取。我在工作台上制作了一个过程并运行它,以将数据插入表映射。

select ac_no,department,rank,email,(select department,email from employee where rank=05)head from employee where rank=08;


但是,如果我运行此查询,结果为subquery returns more than 1 row

抱歉,如果我问基本问题,但我真的不知道该怎么做。

最佳答案

这样尝试

select ac_no,department,rank,email from employee where rank = 08 and where department =  all(select department from employee group by department)

10-08 18:55