我有這樣的一個表:INSERT INTO ... SELECT ... ON DUPLICATE KEY
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場等於存在於表CURENT用戶的份額的數量和需要更新
我們的目標是讓用戶的列表與他們的數字行動和行動d總字段,它是用戶完成的操作的總和。
VALUES(nb_share)接縫給我所有用戶的nb_share總數,而不是當前用戶的總數。
你有想法解決這個問題嗎?
感謝