✏️ 正在编辑: 1945.sql
路径:
/srv/systems_dir/yuppiecred-lidernegocios/data/database/1945.sql
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * Author: yuppie * Created: 21/03/2018 */ INSERT INTO `tb_callcenter_beneficios` (`cpf_cliente`, `beneficio`, `margem_livre`, `margem_cartao`, `mr`, `especie`, `origem`) SELECT cpf, matricula, margem_livre, valor_saque, valor_beneficio, especie, 'CADASTRO' AS origem FROM ( SELECT cpf, matricula, margem_livre, valor_saque, valor_beneficio, especie FROM tb_callcenter_base WHERE matricula <> '' AND matricula IS NOT NULL) AS tmp WHERE NOT EXISTS ( SELECT b.beneficio FROM tb_callcenter_beneficios b WHERE b.beneficio = tmp.matricula); SET @row_number = 0; CREATE TABLE tmp_delete_duplicados AS SELECT (@row_number:=@row_number + 1) AS num, count_id, base.* FROM tb_callcenter_base AS base INNER JOIN (SELECT cpf, COUNT(id) AS count_id FROM tb_callcenter_base GROUP BY cpf HAVING COUNT(id) > 1) temp ON base.cpf = temp.cpf HAVING MOD(num, count_id) <> 0 ORDER BY num; create table tb_callcenter_base_bkp like tb_callcenter_base; insert into tb_callcenter_base_bkp select * from tb_callcenter_base; DELETE base.* FROM tb_callcenter_base AS base INNER JOIN tmp_delete_duplicados AS duplicados ON base.id = duplicados.id ALTER TABLE `tmp_delete_duplicados` DROP COLUMN `count_id`, DROP COLUMN `num`; DROP tmp_delete_duplicados; ALTER TABLE `tb_callcenter_emprestimos_clientes` ADD COLUMN `base_cliente_id` INT(11) NULL DEFAULT '0' AFTER `cpf_cliente`; UPDATE tb_callcenter_emprestimos_clientes emprestimos INNER JOIN tb_callcenter_base AS base ON emprestimos.cpf_cliente = base.cpf SET emprestimos.base_cliente_id = base.id;
💾 保存文件
← 返回文件管理器