如果我理解正确,您正在尝试合并两个表并添加按“天”分组的“计数”字段的值(可能是“用户”)。
有几种方法可以完成我认为您正在尝试做的事情。在此方法中,我们将创建一个表并使用 UNION ALL、SUM 和 GROUP BY 插入 Table_A 和 Table_B 的值。
create table `Table_C` (
`id` int unsigned primary key auto_increment,
`day` varchar(16),
`count` integer
);
INSERT INTO `Table_C`
SELECT * FROM (
SELECT
0 AS `id`,
`day`,
SUM(`count`)
FROM (
SELECT `a`.`day` AS `day`, `a`.`count` AS `count` FROM `Table_A` `a`
UNION ALL
SELECT `b`.`day` AS `day`, `b`.`count` AS `count` FROM `Table_B` `b`
) AS `u`
GROUP BY `u`.`day`
ORDER BY `u`.`day`
) AS `t1`;
但是,这里不考虑活动的“用户”。