1

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

我有这张桌子:员工

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

我想使用过程将表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

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

4

2 回答 2

0

像这样试试

select ac_no,department,rank,email from employee where rank = 08 and where department =  all(select department from employee group by department) 
于 2012-09-19T05:04:49.023 回答
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 的员工属于同一部门

于 2012-09-19T06:13:55.250 回答