我有这样的查询:
INSERT INTO products_analysis_cache (products_id, group_styles, group_finishing, group_elements, group_materials, group_watchlist)
SELECT p.products_id,
CONCAT(',', GROUP_CONCAT(shp.styles_id), ',') AS group_styles,
group_finishing,
group_elements,
group_materials,
group_watchlist
FROM products p
LEFT JOIN styles_has_products shp ON shp.products_id = p.products_id
LEFT JOIN (
SELECT pue.products_id, CONCAT(',', GROUP_CONCAT(pue.elements_id),',',IFNULL(GROUP_CONCAT(paue.elements_id),0), ',') AS group_elements
FROM products_use_elements pue
LEFT JOIN products_articles_use_elements paue ON paue.products_use_elements_id=pue.products_use_elements_id
GROUP BY pue.products_id
) subquery_1 ON subquery_1.products_id = p.products_id
LEFT JOIN (
SELECT ptpm.products_id, CONCAT(',', GROUP_CONCAT(ptpm.products_materials_id), ',') AS group_materials
FROM products_to_products_materials ptpm
GROUP BY ptpm.products_id
) subquery_2 ON subquery_2.products_id = p.products_id
LEFT JOIN (
SELECT muwp.products_id, CONCAT(',', GROUP_CONCAT(muwp.user_id), ',') AS group_watchlist
FROM minierp_users_watch_products muwp
GROUP BY muwp.products_id
) subquery_3 ON subquery_3.products_id = p.products_id
LEFT JOIN (
SELECT products_id, fg+fh+fb+fo+fr AS group_finishing FROM
(SELECT p.products_id
,IF(SUM(finishing_goldplate)>0,1,0) fg
,IF(SUM(finishing_hammer)>0,11,0) fh
,IF(SUM(finishing_brush)>0,111,0) fb
,IF(SUM(finishing_oxid)>0,1111,0) fo
,IF(SUM(finishing_rosegoldplate)>0,11111,0) fr
FROM products p
INNER JOIN products_use_elements pue ON pue.products_id = p.products_id
GROUP BY pue.products_id
) dt
) subquery_4 ON subquery_4.products_id = p.products_id
GROUP BY p.products_id ORDER BY p.products_id DESC;
但是当我跑的时候。 Mysql抛出错误
[HY000][1260] Row 8036 was cut by GROUP_CONCAT()
这是我要插入的表格。
CREATE TABLE `products_analysis_cache` (
`products_id` int(11) NOT NULL,
`group_styles` longtext NOT NULL,
`group_finishing` longtext NOT NULL,
`group_elements` longtext NOT NULL,
`group_materials` longtext NOT NULL,
`group_watchlist` longtext NOT NULL,
PRIMARY KEY (`products_id`),
KEY `idx_products_id` (`products_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
我已经为每一列提供了LONGTEXT以接受长文本,但仍然会出现同样的错误。
我做错了什么?
感谢您的帮助。 编辑: 我根据mysql文档将group_concat_max_len设置为可用的最大值(18446744073709551615),它仍然显示错误'被GROUP_CONCAT()'
切断答案 0 :(得分:1)
尝试按照here的说明增加group_concat_max_len
的值。这就是它所说的:
GROUP_CONCAT()的最大允许结果长度(以字节为单位) 功能。默认值为1024。
答案 1 :(得分:0)
您可以将group_concat_max_len变量设置为更大的值。或者使用GROUP_CONCAT(DISTINCT ...)
来缩短结果。