0

我有一个看起来像这样的查询:

SELECT 
    *, 
    GROUP_CONCAT(DISTINCT web_order_item.od_pcode) AS items, 
    GROUP_CONCAT(DISTINCT woi_id) AS woi_ids 
    FROM web_order 
JOIN web_order_item USING(od_id) 
JOIN customer_master ON customer_master.VC_CUSTOMER_CODE = web_order.p_vendor 
LEFT JOIN production_item ON production_item.ItemID IN (GROUP_CONCAT(DISTINCT woi_id)) AND QCStatus <> 'received' 
WHERE
   web_order.od_date >= FROM_UNIXTIME(1357257600) 
   AND web_order.od_date <= FROM_UNIXTIME(1359936000) 
   AND web_order.od_id > 0 
   AND 1 
GROUP BY web_order.od_id 
ORDER BY web_order.od_id DESC 

此查询引发错误

一般错误:1111 无效使用组功能

我在这里想念什么?谢谢

4

2 回答 2

0
SELECT 
*, 
GROUP_CONCAT(DISTINCT web_order_item.od_pcode) AS items, 
GROUP_CONCAT(DISTINCT woi_id) AS woi_ids 
FROM web_order 
JOIN web_order_item USING(od_id) 
JOIN customer_master ON customer_master.VC_CUSTOMER_CODE = web_order.p_vendor 
LEFT JOIN production_item ON production_item.ItemID IN (GROUP_CONCAT(DISTINCT woi_id))     AND QCStatus <> 'received' 
WHERE
web_order.od_date >= FROM_UNIXTIME(1357257600) 
AND web_order.od_date <= FROM_UNIXTIME(1359936000) 
AND web_order.od_id > 0 
AND 1 
GROUP BY items, woi_ids 
ORDER BY web_order.od_id DESC 

跳这有帮助

参考http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html

于 2013-02-13T16:55:13.833 回答
0

您正在选择完整的原始记录,然后在 web_order_item 上进行分组连接,由于 DISTINCT 属性,这将产生单行,如果有多个记录,您将在那里分组,然后再次尝试分组...无论如何,您最后分组的目的是什么?没有聚合,一个 order by 就足够了。取出 group by...或更改 group by 以在组连接之前包含所有相关项目...

于 2013-02-13T16:49:54.917 回答