java吧 关注:1,239,477贴子:12,710,529
  • 4回复贴,共1
我该如何将这组数据通过名称分组,并且实现相同名称产品的count数量相加呢


IP属地:江苏1楼2022-04-26 21:22回复
    SET NAMES utf8mb4;
    SET FOREIGN_KEY_CHECKS = 0;
    DROP TABLE IF EXISTS `order_detail`;
    CREATE TABLE `order_detail` (
    `id` int(6) NOT NULL AUTO_INCREMENT,
    `goods_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
    `goods_info` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
    `order_price` double(8, 2) NULL DEFAULT NULL,
    `goods_count` int(4) NULL DEFAULT NULL,
    `total_price` double(10, 4) NULL DEFAULT NULL,
    `username` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
    `message` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '用户留言',
    `phone` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
    `order_destination` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
    `order_status` int(2) NULL DEFAULT NULL,
    `pay_method` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '支付方式:支付宝、微信',
    `create_time` datetime(0) NULL DEFAULT NULL,
    `update_time` datetime(0) NULL DEFAULT NULL,
    `user_id` int(6) NULL DEFAULT NULL,
    `order_id` int(6) NULL DEFAULT NULL,
    `goods_id` int(6) NULL DEFAULT NULL,
    PRIMARY KEY (`id`) USING BTREE
    ) ENGINE = InnoDB AUTO_INCREMENT = 1011 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '订单详情表' ROW_FORMAT = Dynamic;
    -- ----------------------------
    -- Records of order_detail
    -- ----------------------------
    INSERT INTO `order_detail` VALUES (1001, 'p50', 'p50.jpg', 7000.00, 1, 7000.0000, 'testuser', '1111', '13333333333', '43563456', 4, '支付宝', '2022-03-07 20:41:39', '2022-03-07 20:41:39', 2, 10001, 4);
    INSERT INTO `order_detail` VALUES (1002, 'xiaomi10', 'xiaomi10.jpg', 2999.00, 1, 2999.0000, 'testuser', '11', '13333333333', '32452315', 4, '微信', '2022-03-07 20:41:40', '2022-03-07 20:41:41', 2, 10002, 3);
    INSERT INTO `order_detail` VALUES (1004, '小板凳', '亮朵凳子家居好物清单小百货用品大全日用生活实用具家庭创意神器.jpg', 10.00, 21, 210.0000, 'admin', '希望快点送达', '14444444444', 'asfdg', 1, '支付宝', '2022-03-23 08:32:16', '2022-03-23 08:32:16', 1, 10008, 47);
    INSERT INTO `order_detail` VALUES (1005, 'Mate X Pro 11代酷睿', '华为笔记本电脑MateBook X Pro 2022款 14.2英寸11代英特尔酷睿i5i7锐炬显卡3.1K触控原色全面屏超级终端.jpg', 9499.00, 14, 132986.0000, 'admin', 'aaaa', '14444444444', 'xxxxxxxx', 1, '支付宝', '2022-04-11 13:42:40', '2022-04-11 13:42:40', 1, 10009, 21);
    INSERT INTO `order_detail` VALUES (1006, '飞天茅台53度500ml', '贵州茅台酒53度飞天茅台第十届酒博会500ml晟藏老酒陈酒白酒酒水.jpg', 3800.00, 11, 41800.0000, 'ldh', 'dddd', '18888888888', 'yyyyyyy', 1, '支付宝', '2022-04-11 13:49:39', '2022-04-11 13:49:39', 3, 10010, 25);
    INSERT INTO `order_detail` VALUES (1007, '德芙巧克力', '德芙巧克力旗舰店3碗装零食小吃黑白牛奶巧克力组合装休闲食品.jpg', 23.00, 11, 253.0000, 'ldh', 'aass', '18888888888', 'y45hr4', 1, '微信', '2022-04-11 13:50:22', '2022-04-11 13:50:22', 3, 10011, 32);
    INSERT INTO `order_detail` VALUES (1008, '怀旧干脆面统一', '统一小当家干脆面48袋整箱充饥怀旧速食品干吃方便面休闲零食小吃.jpg', 27.00, 100, 2700.0000, 'xx', '123456', '12345678991', '沙堤坳', 1, '微信', '2022-04-11 13:53:55', '2022-04-11 13:53:55', 5, 10012, 35);
    INSERT INTO `order_detail` VALUES (1009, '小米12', 'xiaomi12.jpg', 4999.00, 88, 439912.0000, 'admin', '1234541346', '14444444444', '沙堤坳11224', 1, '支付宝', '2022-04-11 19:16:46', '2022-04-11 19:16:46', 1, 10013, 2);
    INSERT INTO `order_detail` VALUES (1010, '小米12', 'xiaomi12.jpg', 4999.00, 13, 64987.0000, 'admin', '111', '14444444444', '111', 1, '支付宝', '2022-04-26 20:35:02', '2022-04-26 20:35:02', 1, 10014, 2);
    SET FOREIGN_KEY_CHECKS = 1;


    IP属地:江苏2楼2022-04-26 21:25
    回复
      SELECT goods_name,SUM(goods_count) AS goods_num FROM order_detail GROUP BY goods_name;


      IP属地:陕西3楼2022-04-26 21:36
      收起回复
        idea不错哦


        IP属地:浙江来自Android客户端4楼2022-04-27 08:20
        回复