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;

  • 相关阅读:
    rabbitmq入门
    php7.2 安装redis扩展
    php安装扩展的几种方法
    yum安装php7.2
    相关报错
    [枚举]P1089 津津的储蓄计划
    [DFS]排列的生成
    [枚举]P1085 不高兴的津津
    [模拟]P1047 校门外的树
    [模拟]P1046 陶陶摘苹果
  • 原文地址:https://www.cnblogs.com/gendway/p/11775886.html
Copyright © 2011-2022 走看看