表映射mysql

时间:2012-09-19 04:55:35

标签: php mysql mysql-workbench

我有一个问题而且我的朋友说我必须使用表映射...但我不知道什么是表映射,我不知道我将要做什么,是对还是不对< / p>

我有这张桌子:员工

+-------+------------+------+-------------------------+
| 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          |
+-------+------------+------+-------------------------+

从表员工上的数据我必须插入表映射

目标是获得排名为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 |
+-------+---------------+------------+------------------------------+

我想使用过程将表员工中的数据处理成表映射,但我不知道如何获取。我在工作台上创建一个过程并运行它,将数据插入到表映射中。

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

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

2 个答案:

答案 0 :(得分:0)

试试这个

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

答案 1 :(得分:0)

(select ac_no,department,rank,email from employee where rank=8) UNION (select ac_no,department,rank,email from employee where (rank,department) in (select rank,department from employee where rank=5 group by department having count(*)>1)) 

返回所有员工的数据:

1)等级为8,与部门无关

2)等级5至少有一名员工,等级5属于同一部门