SQLite 如何通过查询引用列名
SQLite how to refer to column name by a query
我想做的基本上就是
SELECT (SELECT fields FROM tableB WHERE interest=yes) FROM tableA
为什么我不能这样做?
解决方法是什么?
示例:
我得到了这样的 tablea
time|c1|c2|c3
---------------
0.0 |1 |11|111
1.0 |2 |22|222
2.0 |3 |33|333
tableb 像这样
field| interes
--------------
C1 |yes
C2 |yes
C3 |no
我希望能够像这样放置命令
select (select field from tableb where interest=yes) from tablea where time=1.0
这给了我
2|22
问题的核心是它不允许我通过查询结果引用 column_names。 :(
根据您所写的内容,我猜测您希望从 tableA
中检索可变的字段列表(其中字段列表是从 tableB
中检索的)。
这在 SQL 中是不可能的。您将需要进行 2 次调用,第一个是检索字段列表,第二个是您生成了一个 SQL 语句,其中包含第一次调用中的显式字段列表。
我想做的基本上就是
SELECT (SELECT fields FROM tableB WHERE interest=yes) FROM tableA
为什么我不能这样做? 解决方法是什么?
示例: 我得到了这样的 tablea
time|c1|c2|c3
---------------
0.0 |1 |11|111
1.0 |2 |22|222
2.0 |3 |33|333
tableb 像这样
field| interes
--------------
C1 |yes
C2 |yes
C3 |no
我希望能够像这样放置命令
select (select field from tableb where interest=yes) from tablea where time=1.0
这给了我
2|22
问题的核心是它不允许我通过查询结果引用 column_names。 :(
根据您所写的内容,我猜测您希望从 tableA
中检索可变的字段列表(其中字段列表是从 tableB
中检索的)。
这在 SQL 中是不可能的。您将需要进行 2 次调用,第一个是检索字段列表,第二个是您生成了一个 SQL 语句,其中包含第一次调用中的显式字段列表。