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;

posted on 2019-11-01 11:12  gendway  阅读(104)  评论(0编辑  收藏  举报