【问题标题】:GROUP_CONCAT not working with left joinGROUP_CONCAT 不适用于左连接
【发布时间】:2015-05-28 23:48:11
【问题描述】:

此查询显示错误: #1054 - 'on 子句'中的未知列 'sp.spot_id'

查询:

SELECT product.*,sp.sp_name FROM `product` 
     left join spot_selling on product.product_id=spot_selling.product_id 
      AND spot_selling.end_time >= now() 
      AND spot_selling.start_time <= now() 
      AND spot_selling.status='1' 
    left join(select GROUP_CONCAT(s.name SEPARATOR ',') as sp_name 
from spot s group by s.spot_id) sp on sp.spot_id=spot_selling.spot_id 
WHERE product.user_id='26' AND product.status!='6'

【问题讨论】:

  • 它是如何“不工作”的?

标签: mysql left-join group-concat


【解决方案1】:

我认为你只需要在子查询中使用spot_id,所以有一些东西可以加入:

SELECT product.*, sp.sp_name
FROM `product` left join
      spot_selling
      on product.product_id=spot_selling.product_id AND
         spot_selling.end_time >= now() AND
         spot_selling.start_time <= now() AND
         spot_selling.status = '1' left join
      (select spot_id, GROUP_CONCAT(s.name SEPARATOR ',') as sp_name 
--------------^
       from spot s
       group by s.spot_id
      ) sp
      on sp.spot_id = spot_selling.spot_id 
WHERE product.user_id = '26' AND product.status <> '6'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-25
    • 1970-01-01
    • 2017-11-28
    • 2016-02-27
    • 2018-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多