0

我“认为”我看到了这个问题,但不知道如何解决它

得到了一些很好/快速的帮助来理顺我的查询,但现在我收到了这个错误: 'where子句'中的未知列'caet.entity_id'

错误出现在第三个 select 语句中。我想说>>选择caev.entity_id字段匹配caet.entity_id的值。我检查过,拼写正确,并且这些字段在两个表中。

这应该工作,我需要另一个加入吗?

select c.*, 
(
select caet.value 
from customer_address_entity_text caet 
where cae.entity_id = caet.value_id 
and caet.attribute_id = 23
) as test,
(
select caev.value 
from customer_address_entity_varchar caev 
where caet.entity_id = caev.entity_id 
and caev.attribute_id = 23
) as two
from customer_entity c
join customer_address_entity cae on c.`entity_id` = cae.`parent_id`
where store_id = 15

下面的查询显示了我尝试过的内部连接,但仍然出现错误:

select c.*, 
(
select caet.value 
from customer_address_entity_text caet 
where cae.entity_id = caet.value_id 
and caet.attribute_id = 23
) as test,
(
select caev.value 
from customer_address_entity_varchar caev 
where caet.entity_id = caev.entity_id
and caev.attribute_id = 23
) as two
from customer_entity c
join customer_address_entity cae on c.`entity_id` = cae.`parent_id`
INNER JOIN customer_address_entity_text CAET ON CAET.id = CAEV.id 
where store_id = 8
4

1 回答 1

0

CAEV 不在外部环境中。所以问题是“CAET.id = CAEV.id”。您应该在外部上下文中连接所有表并在内部上下文中选择。但是内部连接不起作用。使用外连接。也许你可以在下面使用:

SELECT     c.*, caet.value AS test, caev.value AS two
FROM         customer_entity AS c INNER JOIN
                  customer_address_entity AS cae ON c.entity_id = cae.parent_id LEFT OUTER JOIN
                  customer_address_entity_text AS caet ON cae.entity_id = caet.value_id AND caet.attribute_id = 23 LEFT OUTER JOIN
                  customer_address_entity_varchar AS caev ON cae.entity_id = caev.entity_id AND caev.attribute_id = 23
WHERE     (store_id = 15)
于 2013-08-12T08:02:40.977 回答