zoukankan      html  css  js  c++  java
  • mysql增删改查

    1、联表更新:

    UPDATE es_risk_monitor_detail t10,
    (
    SELECT
    t1.bill_code,
    t3.area_code
    FROM
    `es_risk_monitor_detail` t1
    LEFT JOIN cdh_customer t2 ON t1.bill_code = t2.customer_code
    LEFT JOIN tm_department_ccm t3 ON t2.current_department = t3.dept_code
    WHERE
    date_format( t1.create_time, '%Y-%m-%d' ) = date_format( NOW( ), '%Y-%m-%d' )
    ) t11
    SET t10.area_code = t11.area_code
    WHERE
    t10.bill_code = t11.bill_code;

    2、联表增加
    INSERT INTO archives_blacklist_detail_info_del SELECT t1.* from archives_blacklist_detail_info t1,(SELECT
    zbill_code 
    FROM
    archives_blacklist_detail_info 
    WHERE
    (zbill_data_source not like '%人工导入%' or zbill_data_source is null)
    and DATEDIFF(now(),remove_time)<=7
    GROUP BY
    zbill_code) t2 WHERE t1.zbill_code=t2.zbill_code AND DATE_FORMAT( t1.create_time, '%Y-%m-%d' ) = DATE_FORMAT( now(), '%Y-%m-%d' ) and t1.apply_join_operator='系统' and t1.risk_status=1;

    3、联表删除
    delete t1 from archives_blacklist_detail_info t1,(SELECT
    zbill_code
    FROM
    archives_blacklist_detail_info
    WHERE
    (zbill_data_source not like '%人工导入%' or zbill_data_source is null)
    and datediff(now(),remove_time)<=7
    GROUP BY
    zbill_code) t2 WHERE t1.zbill_code=t2.zbill_code AND DATE_FORMAT( t1.create_time, '%Y-%m-%d' ) = DATE_FORMAT( now(), '%Y-%m-%d' ) and t1.apply_join_operator='系统' and t1.risk_status=1;

    4、添加列:

    ALTER TABLE table ADD COLUMN customer_code varchar(20) NULL COMMENT '名字' AFTER bill_code;

  • 相关阅读:
    汉诺塔实现笔记
    python-nmap的函数学习
    字符串匹配的KMP算法(转)
    QT下的贪吃蛇
    PentestBox在win10里打不开工具
    Dalvik虚拟机执行流程图
    用dx生成dex时遇到class name does not match path
    python3 小工具
    python3的Cryptodome
    前端学习笔记 day02 CSS
  • 原文地址:https://www.cnblogs.com/gendway/p/11775886.html
Copyright © 2011-2022 走看看