Mār*_*ovs 1 mysql sql subquery mysql-error-1054
我需要在子查询中执行子查询,导致'where子句'中的"未知列't1.product_id'".在我的例子中,它在第7行.如何解决这个问题呢?
SELECT *,product_id id,
(SELECT GROUP_CONCAT (value ORDER By `order` ASC SEPARATOR ', ')
FROM (
SELECT `order`,value
FROM slud_data
LEFT JOIN slud_types ON slud_types.type_id=slud_data.type_id
WHERE slud_data.product_id = t1.product_id
AND value!='' AND display=0
LIMIT 3
) tmp) text
FROM slud_products t1
WHERE
now() < DATE_ADD(date,INTERVAL +ttl DAY) AND activated=1
ORDER BY t1.date DESC
Run Code Online (Sandbox Code Playgroud)
我发现在超过2个深度选择的查询中使用变量更为舒适.
SELECT *,@product := product_id id,
(SELECT GROUP_CONCAT (value ORDER By `order` ASC SEPARATOR ', ')
FROM (
SELECT `order`,value
FROM slud_data
LEFT JOIN slud_types ON slud_types.type_id=slud_data.type_id
WHERE slud_data.product_id = @product
AND value!='' AND display=0
LIMIT 3
) tmp) text
FROM slud_products t1
WHERE
now() < DATE_ADD(date,INTERVAL +ttl DAY) AND activated=1
ORDER BY t1.date DESC
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5798 次 |
最近记录: |