/ 中存储网

MYSQL主键不存在时插入数据否则更新(on duplicate key update)

2014-07-13 16:28:28 来源:中存储网
INSERT  INTO keyword_srch_CNT_TOP_100_MONTH_20130301190944(CGI,ACCESS,IP,REF,UA,HIT) VALUES
('getlogcollect.cgi','2013-03-01 00:00:00','172.26.176.95','','Firefox','100')
,
('navisearchif7.cgi','2013-03-01 00:00:00','172.26.176.95','','Firefox','200'),
('navisearchif7.cgi','2013-03-01 00:00:00','172.26.176.95','','Firefox','200'),
('navisearchif7.cgi','2013-03-01 00:00:00','172.26.176.95','','Firefox','200'),
('navisearchif7.cgi','2013-03-01 00:00:00','172.26.176.95','','Firefox','200'),
('keywordmap.cgi','2013-03-01 00:00:00','172.26.176.95','','Firefox','2918')
ON DUPLICATE KEY UPDATE ACCESS=ACCESS, datacnt=datacnt+1

遇到一个问题当表中有一个字段是日期类型时用 ON DUPLICATE KEY UPDATE 做更新的数据时日期会变掉,最后把
ON DUPLICATE KEY UPDATE ACCESS=ACCESS, datacnt=datacnt+1 加上解决了