我有一个如下所示的查询:
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无效使用群组功能
我在这里缺少什么?感谢
答案 0 :(得分:0)
您完整地选择了原始记录,然后您在web_order_item上进行了一个组连接,由于DISTINCT属性,如果有多个属性,这将产生一行记录,你在那里进行分组,然后再尝试分组......你到底分组了什么?没有聚合,订单就足够了。通过...取出小组或更改小组以在小组结束前包括所有相关项目...
答案 1 :(得分: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