首页 > 已解决:删掉values即可 group by 可以查询出结果却无法作为values进行插入

已解决:删掉values即可 group by 可以查询出结果却无法作为values进行插入

用select xxx group by查询出了结果 却无法将其作为结果进行插入

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` 
【热门文章】
【热门文章】