2010-04-04 56 views
1

我想介紹一個加入到這個查詢:通過添加介紹加入此查詢,可能嗎?

LEFT JOIN `exp_channel_titles` 
ON (`n`.`entry_id`=`exp_channel_titles`.`entry_id`) 
後FROM語句

SELECT `n`.*, round((`n`.`rgt` - `n`.`lft` - 1)/2, 0) AS childs, 
count(*) - 1 + (`n`.`lft` > 1) + 1 AS level, 
((min(`p`.`rgt`) - `n`.`rgt` - (`n`.`lft` > 1))/2) > 0 AS lower, 
(((`n`.`lft` - max(`p`.`lft`) > 1))) AS upper 
FROM `exp_node_tree_6` `n`, `exp_node_tree_6` `p`, `exp_node_tree_6` 
WHERE `n`.`lft` 
BETWEEN `p`.`lft` 
AND `p`.`rgt` 
AND (`p`.`node_id` != `n`.`node_id` OR `n`.`lft` = 1) 
GROUP BY `n`.`node_id` 
ORDER BY `n`.`lft` 

...

但是,當我介紹它,它失敗「'條款'中的未知列'n.entry_id'」

是否可以向該查詢添加連接?

任何人都可以幫忙,謝謝!

回答

1

我想你的問題來自於你在表列表末尾添加了連接子句。嘗試

SELECT `n`.*, round((`n`.`rgt` - `n`.`lft` - 1)/2, 0) AS childs, 
count(*) - 1 + (`n`.`lft` > 1) + 1 AS level, 
((min(`p`.`rgt`) - `n`.`rgt` - (`n`.`lft` > 1))/2) > 0 AS lower, 
(((`n`.`lft` - max(`p`.`lft`) > 1))) AS upper 
FROM `exp_node_tree_6` `n` 
    LEFT JOIN `exp_channel_titles` 
    ON (`n`.`entry_id`=`exp_channel_titles`.`entry_id`), 

    `exp_node_tree_6` `p`, 
    `exp_node_tree_6` 
WHERE `n`.`lft` 
BETWEEN `p`.`lft` 
AND `p`.`rgt` 
AND (`p`.`node_id` != `n`.`node_id` OR `n`.`lft` = 1) 
GROUP BY `n`.`node_id` 
ORDER BY `n`.`lft` 

您只能在屬於那些已經在JOIN流中表的ON子句領域引用。

我希望這會幫助你, 傑羅姆·瓦格納

+0

謝謝你這麼多!!!!! – 2010-04-04 13:23:52

+0

你能接受答案嗎?謝謝。傑羅姆 – 2010-04-04 14:22:28

+0

它不會讓我,因爲你太快了......現在已經做了:) – 2010-04-04 14:25:37