查看时将三张表合二为一
我有三个表格,如图所示,我想将其呈现为最后一个表格所示。我不知道如何解决它 - 现在我正在使用三个嵌套调用来显示它。
首先,我循环遍历 Customer
以显示所有这些。在这个循环中,我有一个循环遍历 OrderCustom
,并在其中检查是否存在具有正确 Customer_id
和 的
。CustomerOrderCustom
。 OrderCustom_id
我不仅使用了大量查询,而且视图还显示了 Customer
现在正在使用的 OrderCustom
项目,在本例中为邮政编码。我使用的是 MySQL 5。
I have three tables as seen in this image and I want to present it as seen in the last table. I can't figure out how to solve it - right now I'm using three nestled calls to display it.
First I loop through Customer
to display all of them. Inside this loop I have a loop that goes through OrderCustom
and inside that I check if there is a CustomerOrderCustom
with the right Customer_id
and OrderCustom_id
.
Not only am I using a lot of queries but the view shows OrderCustom
items that now Customer
are using, in this case Zip Code. I'm using MySQL 5.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个实体-属性-值数据库设计。它在设计上不是关系型的,除了最简单的示例之外,您将无法通过关系操作(例如 JOIN)来操纵它。
如果您决定将此非关系数据存储在关系数据库中,则无论您使用什么编程语言,您都将依赖于您自己的代码或某些基于 EAV 的对象序列化和反序列化库。 SQL 对你来说没什么用处。
如果你确实需要在这个项目中使用这样的模型(也就是说,你不能采用关系模型)那么,如果在开发过程中还不算太晚的话,我建议放弃 SQL 并阅读 XML、XPath和 XSLT 可能更适合存储和恢复数据,其中每个条目可以具有不同的结构。
奖励文章: "为什么实体属性值不好”
This is an entity-attribute-value database design. It is not relational in design and you will not be able to manipulate it with relational operations (such as JOINs) except for the most trivial examples.
If you are determined to store this non-relational data in a relational database you'll be dependent on either your own code or some EAV-based object serialization and deserialization library for whatever programming language you're using. SQL will be of little use to you.
If you are really required to use a model like this for this project (that is, you cannot adopt a relational model) then, if it is not too late in the development process, I would suggest abandoning SQL and reading up on XML, XPath, and XSLT which are probably a better fit for storing and recovering data in which each entry can have a different structure.
Bonus Article: "Why Entity-Attribute-Value is bad"