MySql 批量进行数据处理 存储化

INSERT INTO `lc_knowledge_type` ( `createTime`, `modifyTime`, `child`, `image`, `remark`, `sort`, `typeName`, `modifyId`, `ownerId`, `parentId`, `photoId`, `topParentName`, `cateCode`) VALUES(NULL,NULL,'1',NULL,'产地概况','4065','产地概况',NULL,NULL,'4008',NULL,'中药材组','A.1.1');
INSERT INTO `lc_knowledge_type` ( `createTime`, `modifyTime`, `child`, `image`, `remark`, `sort`, `typeName`, `modifyId`, `ownerId`, `parentId`, `photoId`, `topParentName`, `cateCode`) VALUES(NULL,NULL,'1',NULL,'市场需求情况','4066','市场需求情况',NULL,NULL,'4008',NULL,'中药材组','A.1.2');
INSERT INTO `lc_knowledge_type` ( `createTime`, `modifyTime`, `child`, `image`, `remark`, `sort`, `typeName`, `modifyId`, `ownerId`, `parentId`, `photoId`, `topParentName`, `cateCode`) VALUES(NULL,NULL,'1',NULL,'价格成本分析','4067','价格成本分析',NULL,NULL,'4008',NULL,'中药材组','A.1.3');
INSERT INTO `lc_knowledge_type` ( `createTime`, `modifyTime`, `child`, `image`, `remark`, `sort`, `typeName`, `modifyId`, `ownerId`, `parentId`, `photoId`, `topParentName`, `cateCode`) VALUES(,NULL,NULL,'1',NULL,'政策法规','4068','政策法规',NULL,NULL,'4008',NULL,'中药材组','A.1.4');
INSERT INTO `lc_knowledge_type` ( `createTime`, `modifyTime`, `child`, `image`, `remark`, `sort`, `typeName`, `modifyId`, `ownerId`, `parentId`, `photoId`, `topParentName`, `cateCode`) VALUES(NULL,NULL,'0',NULL,'来源及基本形态','4069','来源及基本形态',NULL,NULL,'4065',NULL,'中药材组','A.1.1.1');
INSERT INTO `lc_knowledge_type` ( `createTime`, `modifyTime`, `child`, `image`, `remark`, `sort`, `typeName`, `modifyId`, `ownerId`, `parentId`, `photoId`, `topParentName`, `cateCode`) VALUES(NULL,NULL,'0',NULL,'产地分布','4070','产地分布',NULL,NULL,'4065',NULL,'中药材组','A.1.1.2');
INSERT INTO `lc_knowledge_type` ( `createTime`, `modifyTime`, `child`, `image`, `remark`, `sort`, `typeName`, `modifyId`, `ownerId`, `parentId`, `photoId`, `topParentName`, `cateCode`) VALUES(NULL,NULL,'0',NULL,'产地产量分布','4071','产地产量分布',NULL,NULL,'4065',NULL,'中药材组','A.1.1.3');
INSERT INTO `lc_knowledge_type` ( `createTime`, `modifyTime`, `child`, `image`, `remark`, `sort`, `typeName`, `modifyId`, `ownerId`, `parentId`, `photoId`, `topParentName`, `cateCode`) VALUES(NULL,NULL,'0',NULL,'生产地的政策','4072','生产地的政策',NULL,NULL,'4065',NULL,'中药材组','A.1.1.4');
INSERT INTO `lc_knowledge_type` ( `createTime`, `modifyTime`, `child`, `image`, `remark`, `sort`, `typeName`, `modifyId`, `ownerId`, `parentId`, `photoId`, `topParentName`, `cateCode`) VALUES(NULL,NULL,'0',NULL,'市场主流规格及我司需求的规格等级要求','4073','市场主流规格及我司需求的规格等级要求',NULL,NULL,'4065',NULL,'中药材组','A.1.1.5');
INSERT INTO `lc_knowledge_type` ( `createTime`, `modifyTime`, `child`, `image`, `remark`, `sort`, `typeName`, `modifyId`, `ownerId`, `parentId`, `photoId`, `topParentName`, `cateCode`) VALUES(NULL,NULL,'0',NULL,'产量与需求量关系','4074','产量与需求量关系',NULL,NULL,'4066',NULL,'中药材组','A.1.2.1');
INSERT INTO `lc_knowledge_type` ( `createTime`, `modifyTime`, `child`, `image`, `remark`, `sort`, `typeName`, `modifyId`, `ownerId`, `parentId`, `photoId`, `topParentName`, `cateCode`) VALUES(NULL,NULL,'0',NULL,'主要需求厂家或主要需求品类的情况','4075','主要需求厂家或主要需求品类的情况',NULL,NULL,'4066',NULL,'中药材组','A.1.2.2');
INSERT INTO `lc_knowledge_type` ( `createTime`, `modifyTime`, `child`, `image`, `remark`, `sort`, `typeName`, `modifyId`, `ownerId`, `parentId`, `photoId`, `topParentName`, `cateCode`) VALUES(NULL,NULL,'0',NULL,'我司目前主要供应商','4076','我司目前主要供应商',NULL,NULL,'4066',NULL,'中药材组','A.1.2.3');
INSERT INTO `lc_knowledge_type` ( `createTime`, `modifyTime`, `child`, `image`, `remark`, `sort`, `typeName`, `modifyId`, `ownerId`, `parentId`, `photoId`, `topParentName`, `cateCode`) VALUES(NULL,NULL,'0',NULL,'历史价格分析及未来一年的价格预测','4077','历史价格分析及未来一年的价格预测',NULL,NULL,'4067',NULL,'中药材组','A.1.3.1');
INSERT INTO `lc_knowledge_type` ( `createTime`, `modifyTime`, `child`, `image`, `remark`, `sort`, `typeName`, `modifyId`, `ownerId`, `parentId`, `photoId`, `topParentName`, `cateCode`) VALUES(NULL,NULL,'0',NULL,'种植流程分析','4078','种植流程分析',NULL,NULL,'4067',NULL,'中药材组','A.1.3.2');
INSERT INTO `lc_knowledge_type` ( `createTime`, `modifyTime`, `child`, `image`, `remark`, `sort`, `typeName`, `modifyId`, `ownerId`, `parentId`, `photoId`, `topParentName`, `cateCode`) VALUES(NULL,NULL,'0',NULL,'加工环节分析','4079','加工环节分析',NULL,NULL,'4067',NULL,'中药材组','A.1.3.3');
INSERT INTO `lc_knowledge_type` ( `createTime`, `modifyTime`, `child`, `image`, `remark`, `sort`, `typeName`, `modifyId`, `ownerId`, `parentId`, `photoId`, `topParentName`, `cateCode`) VALUES(NULL,NULL,'0',NULL,'可能对价格产生影响的主要因素','4080','可能对价格产生影响的主要因素',NULL,NULL,'4067',NULL,'中药材组','A.1.3.4');
INSERT INTO `lc_knowledge_type` ( `createTime`, `modifyTime`, `child`, `image`, `remark`, `sort`, `typeName`, `modifyId`, `ownerId`, `parentId`, `photoId`, `topParentName`, `cateCode`) VALUES(NULL,NULL,'0',NULL,'总体成本分析','4081','总体成本分析',NULL,NULL,'4067',NULL,'中药材组','A.1.3.5');
INSERT INTO `lc_knowledge_type` ( `createTime`, `modifyTime`, `child`, `image`, `remark`, `sort`, `typeName`, `modifyId`, `ownerId`, `parentId`, `photoId`, `topParentName`, `cateCode`) VALUES(NULL,NULL,'0',NULL,'供应风险','4082','供应风险',NULL,NULL,'4068',NULL,'中药材组','A.1.4.1');
INSERT INTO `lc_knowledge_type` ( `createTime`, `modifyTime`, `child`, `image`, `remark`, `sort`, `typeName`, `modifyId`, `ownerId`, `parentId`, `photoId`, `topParentName`, `cateCode`) VALUES(NULL,NULL,'0',NULL,'质量风险','4083','质量风险',NULL,NULL,'4068',NULL,'中药材组','A.1.4.2');
INSERT INTO `lc_knowledge_type` ( `createTime`, `modifyTime`, `child`, `image`, `remark`, `sort`, `typeName`, `modifyId`, `ownerId`, `parentId`, `photoId`, `topParentName`, `cateCode`) VALUES(NULL,NULL,'0',NULL,'法规风险','4084','法规风险',NULL,NULL,'4068',NULL,'中药材组','A.1.4.3');



ALTER TABLE lc_knowledge_type AUTO_INCREMENT=4168
SELECT * FROM lc_knowledge_type  WHERE CHAR_LENGTH(cateCode) = 3 AND topParentName="中药材组" AND id > 3999

20条 
最大记录为 4068
DELETE  FROM lc_knowledge_type WHERE id >0
UPDATE lc_knowledge_type SET parentid = NULL

----LIKE 单个匹配字母
SELECT @cateNameDual:=cateCode FROM lc_knowledge_type WHERE cateCode LIKE '_'

----查找父类
SELECT @cateNameDual:=id FROM lc_knowledge_type WHERE CHAR_LENGTH(cateCode) = 3 AND topParentName="中药材组" AND cateCode='A.1' AND id>3999;

-----自连接
SELECT @cateNameDual:=id FROM lc_knowledge_type  WHERE CHAR_LENGTH(cateCode) = 3 AND topParentName="中药材组" AND cateCode='A.1' AND id>3999;

-----查找当前 知识分类的 父类信息
SELECT * FROM lc_knowledge_type AS a,lc_knowledge_type AS b WHERE a.id = b.id AND a.id = 4181 



----批量存储化处理
DROP PROCEDURE IF EXISTS per2;
DELIMITER //
CREATE PROCEDURE per2() 
BEGIN
DECLARE num INT; 
SET num=4065; 
WHILE num < 4066 DO 

SELECT @cateNameDual:=cateCode,@cateNameDual2:=topParentName FROM lc_knowledge_type WHERE CHAR_LENGTH(cateCode) = 3 AND topParentName="中药材组" AND catecode LIKE 'A.2'AND id > 3999;


INSERT INTO `lc_knowledge_type` ( `createTime`, `modifyTime`, `child`, `image`, `remark`, `sort`, `typeName`, `modifyId`, `ownerId`, `parentId`, `photoId`, `topParentName`, `cateCode`) VALUES(NULL,NULL,'1',NULL,'产地概况','4065','产地概况',NULL,NULL,'4008',NULL,'中药材组',CONCAT(CONCAT('A.1.1==',@cateNameDual),@cateNameDual2));


SET num=num+1;
END WHILE;
END;

----执行完上边存储化处理后,再执行以下语句
CALL per2



你可能感兴趣的:(MySql 批量进行数据处理 存储化)