我正在尝试显示志愿者的职责信息以及分配的绩效。 我想显示这些信息。但是,当我运行查询时,它没有从相同的性能中收集不同的日期。而且availability_date也被混淆了。这是正确的查询吗?我不确定这是正确的查询。 你能给我一些反馈吗? 谢谢。
查询在这里。
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
--添加图片-- 结果:
最佳答案
该查询似乎是合理的,因为它在所有表之间都具有适当的连接条件。我不清楚你对结果有什么问题;如果您更详细地解释和/或显示数据的相关子集可能会有所帮助。
但是,既然您说存在与 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/