本文介绍了表结构问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 帮助:-)我看不出这应该如何布局! 考虑汽车租赁公司的情景。他们有汽车。和批次 (全国范围内)和客户。到目前为止,很容易查询其中的每一个。一个客户租用了一辆 的汽车,所以会说租赁。表。一辆车 是一次又一次租用和退回的,所以每辆 车都会有很多租车。要记住的一件事是,汽车没有分配到特定的地段 所以无论是顾客有车还是很多(某处)和 可供出租。 所以问题是如何布置表格(和查询)以找出 a特定车辆的位置?或者说所有车都在哪里。我不认为这是乍一看这么简单。显然,在car表中可以有一个包含LocationId的 列,但这并不表示 是否是LotId或CustomerId。 LotId和CustomerId可能会有一个列,并且一次只填充一个但是没有适合优雅的SQL查询吗? ? 我以为可能有一个LocationIdType字段。它可以设置为 表示LocationId是否是批次。或客户或这允许我 加入批次或客户表,但我想知道是否还有另外的 方式。 是吗足够的信息继续下去?如果它有帮助我可以提供更多细节。 谢谢, 汤姆 解决方案 该部分已经处理,我有一个ID服务分配所有的ID。 谢谢, Tom Help :-) I can''t see how this should be laid out!Consider the scenario of a car rental company. They have "cars" and "lots"(nationwide) and "customers." So far it is easy to query each of these. Acar is rented by a customer so there would be say a "rentals" table. A caris rented and returned over and over so there would be many rentals for eachcar. One thing to remember is that the car isn''t assigned to a specific lotso either the customer has the car or it is in a lot (somewhere) andavailable for rental.So the question is how do I layout the tables (and query) to find out wherea specific car is? Or where all the cars are for that matter. I don''tthink it is as simple as it looks at first glance. Clearly there can be acolumn in the car table containing a LocationId but that wouldn''t indicatewhether it is a LotId or a CustomerId. There could be a column for bothLotId and CustomerId and with only one filled in at a time but that doesn''tlend itself to an elegant SQL query does it?I thought there might be a LocationIdType field. It could be set toindicate whether the LocationId is a "lot" or a "customer" which permits meto join with the lots or customers table but I wondered if there is anotherway.Is that enough information to go on? I can give more details if it helps.Thanks,Tom 解决方案That part is handled, I have an ID "service" which assigns all the Ids.Thanks,Tom 这篇关于表结构问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-21 04:42