我有一张这样的桌子:
CREATE TABLE `UserTmp` (
`user_id` bigint(20) unsigned NOT NULL,
`nb_invit` bigint(20) unsigned DEFAULT '0',
`nb_share` bigint(20) unsigned DEFAULT '0',
`nb_sent` bigint(20) unsigned DEFAULT '0',
`total` bigint(20) unsigned DEFAULT '0',
PRIMARY KEY (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
我想执行 3 个这样的查询(每个表一个,以便拥有 nb_share、nb_invit 和 nb_sent):
INSERT INTO UserTmp (user_id, nb_share)
select user_id, count(share_date) as 'nb_share'
from Share
where share_date between '2012-05-21 00:00:00' and '2012-05-28 00:00:00'
ON DUPLICATE KEY UPDATE nb_share=VALUES(nb_share);
nb_share 字段等于表中存在的当前用户的共享数,需要更新
目标是获得用户列表,其中包含操作数和一个总字段,该字段是用户完成的操作的总和。
VALUES(nb_share) 接缝给我所有用户而不是当前用户的 nb_share 总数。
你有解决这个问题的想法吗?
谢谢