MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
cs5117155
V2EX  ›  MySQL

求一个数据不存在,则根据唯一索引插入对应的数据方法

  •  
  •   cs5117155 · Jul 8, 2021 · 2223 views
    This topic created in 1799 days ago, the information mentioned may be changed or developed.
    CREATE TABLE `test` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `date` date DEFAULT NULL COMMENT '日期',
      `uid` int(11) unsigned DEFAULT NULL COMMENT '用户 id',
      `type` tinyint(1) DEFAULT '-1' COMMENT '类型: 1.代理 2.业务员',
      `order_type` tinyint(1) DEFAULT '1' COMMENT '1 订单 2.快递 3.商城',
      `new_num` int(11) DEFAULT '0' COMMENT '订单数量',
      `express_num` int(11) DEFAULT '0' COMMENT '快递数量',
      `amount` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '订单金额',
      `deposit` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '快递押金金额',
      `pay_amount` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '付款金额',
      PRIMARY KEY (`id`),
    ) ENGINE=InnoDB COMMENT='统计表';
    

    date,uid,type,order_type,组合唯一索引,当数据库不存在这条唯一索引则插入,有则更新 new_num,deposit,pay_amount 相应字段。如何封装这个 sql 函数的方法,语言不限,最好提供 php,或者 js 的语言的版本

    2 replies    2021-07-08 16:07:38 +08:00
    lerry
        1
    lerry  
       Jul 8, 2021
    lwep
        2
    lwep  
       Jul 8, 2021
    replace into 。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5274 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 08:35 · PVG 16:35 · LAX 01:35 · JFK 04:35
    ♥ Do have faith in what you're doing.