gpt4 book ai didi

mysql - 我选择了一些 'GROUP BY'的结果,结果无法插入到我的表中,报1064错误

转载 作者:行者123 更新时间:2023-11-28 23:30:01 25 4
gpt4 key购买 nike

我用“GROUP BY”选择了一些结果,结果无法插入到我的表中,报1064错误

“分组依据”结果完全正确,值与我要插入的列相对应。但是当我尝试在 SQLyog 上插入 SQL 时,它总是显示 1064 错误。

This is the error MySQL shows

sql查询是:

INSERT INTO `admin_sales_list_count` (
`entity_id`,
`sku`,
`comment_count`,
`shaidan_count`,
`sales_count`,
`order_count`,
`update_time`
)
VALUES
SELECT
`product_id` AS `entity_id`,
`sku` AS `sku`,
SUM(`count_record`.`comment_count`) AS `comment_count`,
SUM(`count_record`.`shaidan_count`) AS `shaidan_count`,
SUM(`count_record`.`sales_count`) AS `sales_count`,
SUM(
`count_record`.`comment_count` + `count_record`.`sales_count`
) AS `order_count`,
NOW() AS `update_time`
FROM
(SELECT
`wsoi`.`product_id`,
`wsoi`.`sku`,
0 AS `comment_count`,
0 AS `shaidan_count`,
`wsoi`.`total_qty` AS `sales_count`
FROM
`rder_item` AS `wsoi`
UNION
ALL
SELECT
`acc`.`entity_id` AS `product_id`,
`acc`.`sku`,
`acc`.`comment_count`,
`acc`.`shaidan_count`,
0 AS `sales_count`
FROM
`admin_comment_count` AS `acc`) AS `count_record`
GROUP BY `count_record`.`product_id`

最佳答案

当您从 select 语句中使用 insert into 时,无需指定 VALUES 关键字。尝试以下操作

insert into `admin_sales_list_count`(...)   select ...

关于mysql - 我选择了一些 'GROUP BY'的结果,结果无法插入到我的表中,报1064错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37649234/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com