我有一个问题,我的 friend 说我必须使用表映射...但我不知道什么是表映射,我也不知道我要做的事情是否正确
我有这张表:员工
+-------+------------+------+-------------------------+
| ac_no | department | rank | email |
+-------+------------+------+-------------------------+
| 12ac | 01 | 08 | bla@vla.com |
| 1an4 | 02 | 08 | jla@jla.com |
| dr17 | 01 | 08 | dre@dre.com |
| 13IN | 01 | 05 | adjre@jre.com |
| TE12 | 02 | 05 | drew@dre.com |
| GR45 | 01 | 05 | noide@idea.com |
+-------+------------+------+-------------------------+
我必须从表 employee 上的数据插入到表映射中
目标是获取排名为08的所有数据
+-------+------------+------+-------------------------+
| 12ac | 01 | 08 | bla@vla.com |
| 1an4 | 02 | 08 | jla@jla.com |
| dr17 | 01 | 08 | dre@dre.com |
+-------+------------+------+-------------------------+
然后查找排名为05且属于同一部门的数据,然后获取电子邮件...如果数据超过一个,则电子邮件将与其拆分;
+-------+---------------+------------+------------------------------+
| ac_no |email | department | email |
+-------+---------------+------------+------------------------------+
| 12ac | bla@vla.com | 01 | adjre@jre.com;noide@idea.com |
| 1an4 | jla@jla.com | 02 | drew@dre.com |
| dr17 | dre@dre.com | 01 | adjre@jre.com;noide@idea.com |
+-------+---------------+------------+------------------------------+
我想使用过程将表employee 中的数据处理到表mapping 中,但我不知道如何获取它。我在工作台上制作了一个程序并运行它,以将数据插入到表映射中。
select ac_no,department,rank,email,(select department,email from employee where rank=05)head from employee where rank=08;
但如果我运行此查询,结果子查询返回多于 1 行
抱歉,如果我问的是基本问题,但我真的不知道该怎么做。
最佳答案
这样试试
select ac_no,department,rank,email from employee where rank = 08 and where department = all(select department from employee group by department)
关于php - 表映射 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12488802/