【发布时间】:2016-12-13 02:44:32
【问题描述】:
我有 3 个 Oracle 表用于将演示事务表链接到 Transaction_Customer 和 Transaction_Employee 的项目,如下所示。每笔交易可能涉及多个客户和多个员工。
我正在尝试编写一个 SQL 查询,该查询将列出在一个时期内与多个员工进行过交易的每个 Customer_ID。我希望输出包含每个 Customer_ID 的单行,其中包含一个逗号分隔列表,其中 Employee_ID 与该客户进行了交易。
输出应如下所示:
Customer_ID|Employees
601|007,008,009
将表连接在一起的基本查询如下所示:
select * from transactions t
left join transactions_customer tc
on t.t_id = tc.t_id
left join transactions_employee te
on t.t_id = te.t_id
我怎样才能完成这项任务并让查询按预期工作?
谢谢!
交易
T_ID|Date|Amount
1|1/10/2017|100
2|1/10/2017|200
3|1/31/2017|150
4|2/16/2017|175
5|2/17/2017|175
6|2/18/2017|185
Transactions_Customer
T_ID|Customer_ID
1|600
1|601
1|602
2|605
3|606
4|601
5|607
6|607
Transactions_Employee
T_ID|Employee_ID
1|007
1|008
2|009
3|008
4|009
5|007
6|007
【问题讨论】:
-
您希望输出是什么?请用所需的结果编辑问题。
-
为什么一个客户会在一次交易中出现多次?
标签: sql oracle transactions