mysql - 已解决:删掉values即可 group by 可以查询出结果却无法作为values进行插入
高洛峰
高洛峰 2017-04-17 14:52:40
[MySQL讨论组]

用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` 
高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号