是的,您可以这样做。您需要的诀窍是有两种将表从表服务器中移出的方法。一种方法是..
FROM TABLE A
另一种方法是
FROM (SELECt col as name1, col2 as name 2 FROM ...) B
请注意,select子句及其周围的括号 是 一个表,一个虚拟表。
因此,使用您的第二个代码示例(我猜您希望在此处检索的列):
SELECT a.attr, b.id, b.trans, b.langFROM attribute aJOIN ( SELECt at.id AS id, at.translation AS trans, at.language AS lang, a.attribute FROM attributeTranslation at) b ON (a.id = b.attribute AND b.lang = 1)
请注意,您的真实表
attribute是此联接中的第一个表,而我调用的虚拟表
b是第二个表。
当虚拟表是某种类型的汇总表时,此技术特别方便。例如
SELECt a.attr, b.id, b.trans, b.lang, c.langcountFROM attribute aJOIN ( SELECt at.id AS id, at.translation AS trans, at.language AS lang, at.attribute FROM attributeTranslation at) b ON (a.id = b.attribute AND b.lang = 1)JOIN ( SELECt count(*) AS langcount, at.attribute FROM attributeTranslation at GROUP BY at.attribute) c ON (a.id = c.attribute)
看看情况如何?您已经生成了一个
c包含两列的虚拟表,将其与其他两列连接,将其中一个列用于该
ON子句,并将另一列作为结果集中的一列返回。



