Oracle 多表查询

标签 oracle

我正在尝试显示志愿者的职责信息以及分配的绩效。 我想显示这些信息。但是,当我运行查询时,它没有从相同的性能中收集不同的日期。而且availability_date也被混淆了。这是正确的查询吗?我不确定这是正确的查询。 你能给我一些反馈吗? 谢谢。

enter image description here

查询在这里。

SELECT Production.name, performance.performance_date, volunteer_duty.availability_date, customer.name "Customer volunteer", volunteer.volunteerid, membership.name "Member volunteer", membership.membershipid
FROM Customer, Membership, Volunteer, volunteer_duty, duty, performance_duty, performance, production
WHERE  
Customer.customerId (+) = Membership.customerId AND
Membership.membershipId = Volunteer.membershipId AND
volunteer.volunteerid = volunteer_duty.volunteerid AND
duty.dutyid = volunteer_duty.dutyid AND
volunteer_duty.dutyId = performance_duty.dutyId AND
volunteer_duty.volunteerId = performance_duty.volunteerId AND
performance_duty.performanceId = performance.performanceId AND
Performance.productionId = production.productionId

--添加图片-- 结果: enter image description here

最佳答案

该查询似乎是合理的,因为它在所有表之间都具有适当的连接条件。我不清楚你对结果有什么问题;如果您更详细地解释和/或显示数据的相关子集可能会有所帮助。

但是,既然您说存在与 availability_date 相关的问题,我的第一个想法是您希望在该列上设置一些条件,以确保志愿者可以履行给定的职责特定表演的日期。这可能意味着只需将 volunteer_duty.availability_date = Performance.performance_date 添加到查询条件中即可。

我更一般的建议是从头开始编写查询,一次添加一个表,并使用 ANSI 连接语法。这将使哪些条件与哪些连接相关变得更清楚,如果您一次添加一个表,希望您能看到结果出错的点。

例如,我可能会这样开始:

SELECT production.name, performance.performance_date
  FROM production
       JOIN performance ON production.productionid = performance.productionid

如果这给出了有意义的结果,那么我将继续向 performance_duty 添加联接并运行该查询。等等。

关于Oracle 多表查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10000355/

相关文章:

oracle - 提高 Oracle DELETE 性能的策略

sql - 多个表上的多个 LEFT OUTER JOIN

用于从日期中提取年份的 SQL 查询

sql - ORA-01952 : system privileges not granted to 'ROJIB

sql - 在 Oracle 中计算条件累积总和

c# - 基于 PIVOT 查询的 Oracle View 不是空值

c++ - 如何从 Oracle occi C++ api 记录原始 SQL?

java - 由 : java. lang.ClassNotFoundException : oracle. jdbc.OracleDriver 引起

oracle - 管理 Oracle 同义词

sql - Oracle SQL 按季度计算的美元总和