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;

  • 相关阅读:
    线性代数(不完全)与矩阵合集
    最短路合集
    [SP2878]KNIGHTS
    Noip 提高组系列题解目录
    【code】最小费用最大流(Dinic / zkw) 模板
    题解 DTOJ #1002.调整(tweak)
    题解 DTOJ #1008.生成输入数据 (input)
    题解 DTOJ #3861.基里巴斯(path)
    模板 · ISAP网络流+GAP优化+弧优化
    代码 · DTOJ.飞行员配对方案
  • 原文地址:https://www.cnblogs.com/gendway/p/11775886.html
Copyright © 2011-2022 走看看