前提条件:必须是唯一主键;

CREATE UNIQUE INDEX idx_vote_object ON test_customers_vote (`vote_object`, `vote_object_id`);

         
用一条sql实现“不存在即插入,存在则increase 某字段”的复合功能 – insert into … on duplicate key update
比如:
CREATE UNIQUE INDEX comp ON logs (`site_id`, `time`);

INSERT INTO logs (`site_id`, `time`,`hits`) VALUES (1,"2004-08-09", 15) ON DUPLICATE KEY UPDATE hits=hits+15;

文章来源:http://hi.baidu.com/caoxin_rain/item/7b7139e99f4763e6fb42ba60

相关文章:

  • 2021-09-14
  • 2021-07-05
  • 2022-02-26
  • 2021-05-24
  • 2022-12-23
  • 2021-12-15
  • 2021-10-21
猜你喜欢
  • 2022-12-23
  • 2021-06-09
  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
  • 2021-06-02
  • 2021-09-19
相关资源
相似解决方案