有人可以告诉我为什么不编译吗?
select p.name, p.client_product_id,
(case when c.ancestry is not null
then
(select c1.title
from catalogs c1
where c1.id = c.ancestry) as catalog,
c.title as subcatalog
else
c.title as catalog
end),
image
from products p
inner join product_catalogs pc on p.id = pc.product_id
inner join catalogs c on c.id = pc.catalog_id
inner join images i on i.imageable_id = p.id
where p.active = 1
因为您的CASE
表达是错误的,所以您可以像下面这样重写您的查询;请注意JOIN
已添加了一个额外的
select p.name, p.client_product_id,
(case when c.ancestry is not null then c1.title else c.title end) as catalog,
image
from products p
inner join product_catalogs pc on p.id = pc.product_id
inner join catalogs c on c.id = pc.catalog_id
inner join catalogs c1 on c1.id = c.ancestry //this one
inner join images i on i.imageable_id = p.id
where p.active = 1;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句