Oracle Sql开发人员如何显示null外键

时间:2012-03-26 20:07:01

标签: oracle null

我正在做Oracle数据库项目,该项目称为“剧院预订系统”。 我试图通过Customer_Concession和Member_Concession显示折扣价。 在Ticket表中,Null-able外键是bookingId,cconcessionId和mconcessionId。 我想显示所有票证,即使其中一个id不存在。 我该如何编写SQL? 你可以帮帮我吗? 感谢。

SELECT t.ticketId, pro.name "Production name", PRICE.LEVELID "Price level", 
Price.price "Price", (Price.price - ccons.discountPrice - mcons.discountPrice)
"Discounted Price", t.seatNo "Seat", t.rowNo "Row", t.block "Block",
per.performance_date "Performance date", per.start_time "Start time", 
per.end_time "End time", t.availability "Availability"

FROM Ticket t, Production pro, Performance per, Price, Price_level, 
Booking, Customer, Customer_Concession ccons, Member_concession mcons

WHERE t.performanceid = per.performanceid AND
  t.PRODUCTIONID = Price.PRODUCTIONID AND
  t.levelId = Price.levelId AND
  Price.PRODUCTIONID = pro.PRODUCTIONID AND
  Price.levelId = Price_level.levelId AND
  t.bookingId = Booking.bookingId AND
  Booking.customerId = Customer.customerId AND
  ccons.cconcessionId = t.cconcessionId AND
  mcons.mconcessionId = t.mconcessionId

ORDER BY t.ticketId

2 个答案:

答案 0 :(得分:3)

您正在寻找的是LEFT OUTER JOIN。

有关详情,请访问此网站:http://www.oreillynet.com/network/2002/04/23/fulljoin.html

答案 1 :(得分:2)

...试

WHERE t.performanceid = per.performanceid AND
      t.PRODUCTIONID = Price.PRODUCTIONID AND
        t.levelId = Price.levelId AND
        Price.PRODUCTIONID = pro.PRODUCTIONID AND
        Price.levelId = Price_level.levelId AND
        t.bookingId = Booking.bookingId(+) AND
        Booking.customerId = Customer.customerId(+) AND
        ccons.cconcessionId(+) = t.cconcessionId AND
        mcons.mconcessionId(+) = t.mconcessionId

(注意旧语法)