[英]Match column_name to Column data
I am trying to work with a two (already) generated tables.我正在尝试使用两个(已经)生成的表。 In one table 1 there is a column named column_code
In table 2 the columns are named like the data in column_code
在一个表 1 中有一个名为column_code
的列 在表 2 中,列的名称与column_code
中的数据相同
Per example Table 1:每个示例表 1:
meta_data
----------------------------------
| pid | 1 |
| question | favorite website |
| column_code | AA123ZZ |
----------------------------------
where column_code
has a content named: 'AA123ZZ'
and question is called: what is your favorite website其中column_code
有一个名为: 'AA123ZZ'
的内容,问题是:你最喜欢的网站是什么
Table 2:表 2:
content
-----------------------------------
| id | 4 |
| submit_date | 14-01-2013 |
| AA123ZZ | stackoverflow.com |
-----------------------------------
The content of this table_name AA123ZZ
is for instance " stackoverflow.com "这个 table_name AA123ZZ
的内容例如是“ stackoverflow.com ”
Now what I want is a query where the result will be something like:现在我想要的是一个查询,其结果将类似于:
id: = 1
what is your favorite website: stackoverflow.com
So actually AA123ZZ
stands for this question, I have no other way of matching these together, how can I do this?所以实际上AA123ZZ
代表这个问题,我没有其他方法可以将它们匹配在一起,我该怎么做?
I am sorry I cannot make this any clearer.很抱歉,我无法更清楚地说明这一点。 I got these two tables and indeed they seem to be missing something.我得到了这两张桌子,确实它们似乎缺少了一些东西。
In the content table the table name AA123ZZ
is 'code' for the question.在内容表中,表名AA123ZZ
是问题的“代码”。
The maker of the database should just have placed the question as column name in stead of this code AA123ZZ
.数据库的创建者应该只是将问题作为列名而不是此代码AA123ZZ
。 Now I need to match this code to what is inside meta_data
.现在我需要将此代码与meta_data
中的内容相匹配。
So in meta_data in the question_column you can find: "favorite website" and in the column_code
you will find AA123ZZ
.因此,在 question_column 的 meta_data 中,您可以找到:“最喜欢的网站”,在column_code
中,您会找到AA123ZZ
。
in the content table in the AA123ZZ
column you will find: stackoverflow.com在AA123ZZ
列的内容表中,您会发现: stackoverflow.com
As you can see I cannot match these easily on a inner join.如您所见,我无法在内部连接中轻松匹配这些。
So is there a way to match a column_name from one table to the contents of a column in another table?那么有没有办法将一个表中的 column_name 与另一个表中的列的内容相匹配?
You can't join tables where the column name
itself is variable.您不能连接column name
本身可变的表。 You're going to need to fix the schema here, perhaps to include a foreign key
value to the meta_data
table from the content
table and from there you can do a simple join
on the two tables.您将需要在此处修复架构,可能包括从content
表到meta_data
表的foreign key
,然后您可以从那里对两个表进行简单join
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.