表1:
====================== | id |id_feature| ====================== | 1 | 4 | | 2 | 2 | | 3 | 9 | ======================
Table_feature4
====================== | id | size | ====================== | 1 | 10000 | | 2 | 12000 | | 3 | 8000 | ======================
Table_feature2
====================== | id | radius | ====================== | 1 | 0.9 | | 2 | 2 | | 3 | 3.1 | ======================
我的查询:
SELECT * FROM Table1
LEFT JOIN (SELECT CONCAT("Table_feature",Table1.id_feature)) Feature ON Feature.id = Table1.id_feature
我怎样才能让它发挥作用?有办法吗? 我收到的错误:
/ * SQL错误(1109):未知表' Tabel1'在字段列表中* /
如果我把4个manualy放在CONCAT中而没有别名就说
/ * SQL错误(1248):每个派生表必须有自己的别名* /
如果我别名"(选择CONCAT(" Table_feature",4))功能"在ON条件下抛出此错误。
/ * SQL错误(1054):未知列' Feature.id'在' on条款' * /
我认为问题在于:"(SELECT CONCAT(" Table_feature",4))" ,它应该返回表名Table_feature4,但它只添加一个名为CONCAT的列(" Table_feature",4)
答案 0 :(得分:2)
目前还不清楚预期的输出是什么,但这是我的开始
SELECT t.id,
CASE t.id_feature
WHEN 2 THEN (SELECT size FROM feature2 f WHERE f.id = t.id)
WHEN 4 THEN (SELECT radius FROM feature4 f WHERE f.id = t.id)
END AS feature_value
FROM Table1 t
我的命名略有不同,但这会输出相应id_feature表的id和value列
答案 1 :(得分:0)
在子查询中,您没有table1(在子查询中,外部表名不在范围内)
并且似乎你错过了子查询中的from子句 最后你在子查询中没有id列或别名,所以你没有ON子句的feature.id
尝试使用像例如:
这样的somthingsSELECT *
FROM Table1
LEFT JOIN (
SELECT CONCAT("Table_feature", Table1.id_feature) , table1.id
FROM Table1
) Feature ON Feature.id = Table1.id_feature