MySQL:如何转换为EAV?
假设我有下表:
TABLE: one
===============================
| id | first_name | last_name |
===============================
| 1 | John | Doe |
| 2 | Jane | Smith |
-------------------------------
我想将其转换为 EAV:
TABLE: two
===================================
| id | fk_id | attribute | value |
===================================
| 1 | 1 | first_name | John |
| 2 | 1 | last_name | Doe |
| 3 | 2 | first_name | Jane |
| 4 | 2 | last_name | Smith |
-----------------------------------
注意:
- two.fk_id 值来自 one.id
- 二.attribute 值来自 one.first_name
- 二.value 值来自 one.last_name
我需要创建表表一中的两个,这样我就可以运行一些测试。
Say I have the following table:
TABLE: one
===============================
| id | first_name | last_name |
===============================
| 1 | John | Doe |
| 2 | Jane | Smith |
-------------------------------
I want to convert it to an EAV:
TABLE: two
===================================
| id | fk_id | attribute | value |
===================================
| 1 | 1 | first_name | John |
| 2 | 1 | last_name | Doe |
| 3 | 2 | first_name | Jane |
| 4 | 2 | last_name | Smith |
-----------------------------------
Note:
- two.fk_id values came from one.id
- two.attribute values came from one.first_name
- two.value values came from one.last_name
I need to create table two from table one so I can run some tests.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设two.id是一个自动递增整数,所以我将它留给目标表来分配这些值。
I'm assuming two.id is an autoincrementing integer, so I'll leave it to the target table to assign those values.
看在上帝的份上,不要使用 EAV!!!!
如果您需要,请改用 NoSQL 数据库!
For the love of god, don't use EAV!!!!
If you need that, use a NoSQL database instead!