[关闭]
@wangyupu 2022-08-09T09:51:19.000000Z 字数 18157 阅读 38

广州医保DIP项目分类

在万达的每一天


建立dip原始表

  1. CREATE TABLE `dip1_ys` (
  2. `zdbm` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  3. `zdmc` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  4. `czbm` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  5. `czmc` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL
  6. index(zdbm)
  7. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;dip1_ysdip1_cf

删除诊断编码为空的字段信息

  1. delete from dip1_ys where zdmc is null;

创建dip拆分表

  1. CREATE TABLE `dip1_cf` (
  2. `zdbm` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  3. `zdmc` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  4. `czbm` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  5. `czmc` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  6. `czglbm` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  7. `czglmc` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  8. `cfbz` int(1)
  9. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

操作原理

  1. select substring_index(substring_index('82,83,84,85,86,87',',',help_topic_id+1),',',-1) as Id,
  2. -- 使用substring_index截取字符串help_topic_id是从零开始记录的,代表分隔符,help_topic_id+1代表0+1 代表+1 字符串第一个分隔符之前的所有内容
  3. substring_index('82,83,84,85,86,87',',',help_topic_id +1) as A,
  4. -- 字符串长度为17 其中包含了间隔符逗号
  5. length('82,83,84,85,86,87') AS B,
  6. -- 除去间隔符之后的字段长度
  7. length(replace('82,83,84,85,86,87',',','')) AS C,
  8. -- 结果
  9. help_topic_id AS D,
  10. length('82,83,84,85,86,87')-length(replace('82,83,84,85,86,87',',',''))+1 AS F
  11. from mysql.help_topic
  12. -- 确定循环次数字符串长度根据分隔符确定循环次数 一刀两半 两刀三半
  13. where help_topic_id<(length('82,83,84,85,86,87')-length(replace('82,83,84,85,86,87',',',''))+1)

查询操作编码为null的字段信息 进行转储 2445 条.

  1. insert into dip1_cf select zdbm,zdmc,czbm,czmc,czbm,czmc,0 from dip1_ys where czbm is null

查询完毕之后进行删除操作 2445

  1. delete from dip1_ys where czbm is null

向dip1_cf表中插入不包含/的数据 共计 7175 条

  1. insert into dip1_cf select zdbm,zdmc,czbm,czmc,czbm as czglbm,czmc as czglmc,1 as cfbz from dip1_ys where czbm not like '%/%';

操作完成之后进行将我们已经转换过的编码进行删除 7175

  1. delete from dip1_ys where czbm not like '%/%'

等待上步操作完成之后进行下步操作更新单个操作,对单个操作组进行分析 2823 条数据

  1. insert into dip1_cf
  2. SELECT
  3. a.zdbm,
  4. a.zdmc,
  5. substring_index(substring_index( a.czbm,'/',b.help_topic_id + 1),'/' ,- 1) AS czbm,
  6. substring_index(substring_index( a.czmc,'/',b.help_topic_id + 1),'/' ,- 1) AS czmc,
  7. a.czbm as czglbm,
  8. a.czmc as czglmc,
  9. 2
  10. FROM
  11. dip1_ys a
  12. JOIN mysql.help_topic b ON b.help_topic_id <
  13. (length(a.czbm) - length( replace(a.czbm, '/', '') ) + 1)
  14. where a.czbm like '%/%' and a.czbm not like '%+%'
  15. order by a.zdbm,a.czbm;

拆分结束对我们的单个操作进行删除 916

  1. DELETE from dip1_ys a where a.czbm like '%/%' and a.czbm not like '%+%'

对A+C1/C2组合进行拆分 1018

  1. insert into dip1_cf
  2. SELECT
  3. a.zdbm,
  4. a.zdmc,
  5. concat(REVERSE(SUBSTRING(REVERSE(a.czbm), INSTR(REVERSE(a.czbm), '+'))),
  6. substring_index(substring_index( a.czbm,'/',b.help_topic_id + 1),'/' ,- 1)) AS czbm,
  7. concat(REVERSE(SUBSTRING(REVERSE(a.czmc), INSTR(REVERSE(a.czmc), '+'))),
  8. substring_index(substring_index( a.czmc,'/',b.help_topic_id + 1),'/' ,- 1)) AS czmc,
  9. a.czbm as czglbm,
  10. a.czmc as czglmc,
  11. 3
  12. FROM
  13. dip1_ys a
  14. JOIN mysql.help_topic b ON b.help_topic_id <
  15. (length(a.czbm) - length( replace(a.czbm, '/', '') ) + 1)
  16. where czbm like '%/%' and czbm like '%+%/%' and czbm not like '%/%+%/%' and czbm not like '%+%/%+%'
  17. order by a.zdbm,a.czbm;

拆分结束对我们的A+C1/C2操作进行删除 386

  1. DELETE FROM dip1_ys a where czbm like '%/%' and czbm like '%+%/%' and czbm not like '%/%+%/%' and czbm not like '%+%/%+%'

对C1/C2+A+B 等进行拆分 1032

  1. insert into dip1_cf
  2. SELECT
  3. a.zdbm,
  4. a.zdmc,
  5. concat(substring_index(substring_index( substring_index(a.czbm,'+',1),'/',b.help_topic_id + 1),'/' ,- 1),
  6. substr(a.czbm,instr(a.czbm,'+'))) AS czbm,
  7. concat(substring_index(substring_index( substring_index(a.czmc,'+',1),'/',b.help_topic_id + 1),'/' ,- 1),
  8. substr(a.czmc,instr(a.czmc,'+'))) AS czmc,
  9. a.czbm as czglbm,
  10. a.czmc as czglmc,
  11. 4
  12. FROM
  13. dip1_ys a
  14. JOIN mysql.help_topic b ON b.help_topic_id <
  15. (length(a.czbm) - length( replace(a.czbm, '/', '') ) + 1)
  16. where czbm like '%/%' and czbm like '%/%+%' and czbm not like '%+%/%+%' and czbm not like '%/%+%/%'
  17. order by a.zdbm,a.czbm;

对C1/C2+A+B 等进行拆分过后进行删除操作 396

  1. DELETE FROM dip1_ys a where czbm like '%/%' and czbm like '%/%+%' and czbm not like '%+%/%+%' and czbm not like '%/%+%/%'

对一个加号进行操作 901

  1. insert into dip1_cf
  2. select t1.zdbm,t1.zdmc,CONCAT_WS('+',t1.czbm1,t2.czbm1) as czbm,CONCAT_WS('+',t1.czmc1,t2.czmc1) as czmc,t1.czbm as czglbm , t1.czmc as czglmc, 5 from
  3. (SELECT
  4. a.zdbm,
  5. a.zdmc,
  6. a.czbm,
  7. a.czmc,
  8. substring_index( substring_index( a.czbm1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czbm1,
  9. substring_index( substring_index( a.czmc1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czmc1,
  10. a.czbm as czglbm,
  11. a.czmc as czglmc
  12. FROM
  13. ( SELECT zdbm,zdmc,czbm,czmc, substring_index( czbm, '+', 1 ) AS czbm1,substring_index( czmc, '+', 1 ) AS czmc1 FROM dip1_ys where length(czbm)-length(replace(czbm,'+',''))=1) a
  14. JOIN mysql.help_topic b ON b.help_topic_id < (length( a.czbm1 ) - length( REPLACE ( a.czbm1, '/', '' ) ) + 1
  15. )) t1,
  16. (SELECT
  17. a.zdbm,
  18. a.zdmc,
  19. a.czbm,
  20. substring_index( substring_index( a.czbm1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czbm1,
  21. substring_index( substring_index( a.czmc1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czmc1,
  22. a.czbm as czglbm,
  23. a.czmc as czglmc
  24. FROM
  25. ( SELECT zdbm,zdmc, czbm,czmc, substring_index( czbm, '+', - 1 ) AS czbm1,substring_index( czmc, '+', - 1 ) AS czmc1 FROM dip1_ys where length(czbm)-length(replace(czbm,'+',''))=1 ) a
  26. JOIN mysql.help_topic b ON b.help_topic_id < (length( a.czbm1 ) - length(REPLACE ( a.czbm1, '/', '' ) ) + 1 )) t2
  27. where t1.czbm1<>t2.czbm1
  28. and t1.zdbm=t2.zdbm
  29. and t1.czbm=t2.czbm
  30. order by zdbm,czbm

操作完成之后删除操作编码 为 A1/A2 + B1/B2 数据进行删除 82

  1. DELETE from dip1_ys a where length(czbm)-length(replace(czbm,'+',''))=1

对于两个加号 410

  1. insert into dip1_cf
  2. select t1.zdbm,t1.zdmc,CONCAT_WS('+',t1.czbm1,t2.czbm1,t3.czbm1) as czbm,CONCAT_WS('+',t1.czmc1,t2.czmc1,t3.czmc1) as czmc,t1.czbm as czglbm , t1.czmc as czglmc, 5 from
  3. (SELECT
  4. a.zdbm,
  5. a.zdmc,
  6. a.czbm,
  7. a.czmc,
  8. substring_index( substring_index( a.czbm1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czbm1,
  9. substring_index( substring_index( a.czmc1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czmc1,
  10. a.czbm as czglbm,
  11. a.czmc as czglmc
  12. FROM
  13. ( SELECT zdbm,zdmc,czbm,czmc, substring_index( czbm, '+', 1 ) AS czbm1,substring_index( czmc, '+', 1 ) AS czmc1 FROM dip1_ys where length(czbm)-length(replace(czbm,'+',''))=2) a
  14. JOIN mysql.help_topic b ON b.help_topic_id < (
  15. length( a.czbm1 ) - length( REPLACE ( a.czbm1, '/', '' ) ) + 1
  16. )) t1,
  17. (SELECT
  18. a.zdbm,
  19. a.zdmc,
  20. a.czbm,
  21. a.czmc,
  22. substring_index( substring_index( a.czbm1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czbm1,
  23. substring_index( substring_index( a.czmc1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czmc1,
  24. a.czbm as czglbm,
  25. a.czmc as czglmc
  26. FROM
  27. ( SELECT zdbm,zdmc, czbm,czmc, substring_index(substring_index( czbm, '+', 2 ),'+',-1 )AS czbm1,substring_index(substring_index( czmc, '+', 2 ),'+',-1 )AS czmc1 FROM dip1_ys where length(czbm)-length(replace(czbm,'+',''))=2) a
  28. JOIN mysql.help_topic b ON b.help_topic_id < (
  29. length( a.czbm1 ) - length( REPLACE ( a.czbm1, '/', '' ) ) + 1
  30. )) t2,
  31. (SELECT
  32. a.zdbm,
  33. a.zdmc,
  34. a.czbm,
  35. a.czmc,
  36. substring_index( substring_index( a.czbm1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czbm1,
  37. substring_index( substring_index( a.czmc1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czmc1,
  38. a.czbm as czglbm,
  39. a.czmc as czglmc
  40. FROM
  41. ( SELECT zdbm,zdmc,czbm,czmc, substring_index( czbm, '+', - 1 ) AS czbm1,substring_index( czmc, '+', -1 ) AS czmc1 FROM dip1_ys where length(czbm)-length(replace(czbm,'+',''))=2) a
  42. JOIN mysql.help_topic b ON b.help_topic_id < (
  43. length( a.czbm1 ) - length( REPLACE ( a.czbm1, '/', '' ) ) + 1
  44. )) t3
  45. where t1.czbm1<>t2.czbm1<>t3.czbm1
  46. and t1.zdbm=t2.zdbm
  47. and t2.zdbm=t3.zdbm
  48. and t1.czbm=t2.czbm
  49. and t2.czbm=t3.czbm
  50. order by zdbm,czbm

针对已经转储的数据进行删除 84

  1. DELETE from dip1_ys a where length(czbm)-length(replace(czbm,'+',''))=2

对三个加号进行比较

  1. insert into dip1_cf
  2. select t1.zdbm,t1.zdmc,CONCAT_WS('+',t1.czbm1,t2.czbm1,t3.czbm1,t4.czbm1) as czbm,CONCAT_WS('+',t1.czmc1,t2.czmc1,t1.czmc1,t4.czmc1) as czmc,t1.czbm as czglbm , t1.czmc as czglmc, 5 from
  3. (SELECT
  4. a.zdbm,
  5. a.zdmc,
  6. a.czbm,
  7. a.czmc,
  8. substring_index( substring_index( a.czbm1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czbm1,
  9. substring_index( substring_index( a.czmc1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czmc1,
  10. a.czbm as czglbm,
  11. a.czmc as czglmc
  12. FROM
  13. ( SELECT zdbm,zdmc,czbm,czmc, substring_index( czbm, '+', 1 ) AS czbm1,substring_index( czmc, '+', 1 ) AS czmc1 FROM dip1_ys where length(czbm)-length(replace(czbm,'+',''))=3) a
  14. JOIN mysql.help_topic b ON b.help_topic_id < (
  15. length( a.czbm1 ) - length( REPLACE ( a.czbm1, '/', '' ) ) + 1
  16. )) t1,
  17. (SELECT
  18. a.zdbm,
  19. a.zdmc,
  20. a.czbm,
  21. a.czmc,
  22. substring_index( substring_index( a.czbm1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czbm1,
  23. substring_index( substring_index( a.czmc1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czmc1,
  24. a.czbm as czglbm,
  25. a.czmc as czglmc
  26. FROM
  27. ( SELECT zdbm,zdmc, czbm,czmc, substring_index(substring_index( czbm, '+', 2 ),'+',-1 )AS czbm1,substring_index(substring_index( czmc, '+', 2 ),'+',-1 )AS czmc1 FROM dip1_ys where length(czbm)-length(replace(czbm,'+',''))=3) a
  28. JOIN mysql.help_topic b ON b.help_topic_id < (
  29. length( a.czbm1 ) - length( REPLACE ( a.czbm1, '/', '' ) ) + 1
  30. )) t2,
  31. (SELECT
  32. a.zdbm,
  33. a.zdmc,
  34. a.czbm,
  35. a.czmc,
  36. substring_index( substring_index( a.czbm1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czbm1,
  37. substring_index( substring_index( a.czmc1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czmc1,
  38. a.czbm as czglbm,
  39. a.czmc as czglmc
  40. FROM
  41. ( SELECT zdbm,zdmc,czbm,czmc, substring_index(substring_index( czbm, '+', -2 ),'+',1 )AS czbm1,substring_index(substring_index( czmc, '+', 2 ),'+',-1 )AS czmc1 FROM dip1_ys where length(czbm)-length(replace(czbm,'+',''))=3) a
  42. JOIN mysql.help_topic b ON b.help_topic_id < (
  43. length( a.czbm1 ) - length( REPLACE ( a.czbm1, '/', '' ) ) + 1
  44. )) t3,
  45. (SELECT
  46. a.zdbm,
  47. a.zdmc,
  48. a.czbm,
  49. a.czmc,
  50. substring_index( substring_index( a.czbm1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czbm1,
  51. substring_index( substring_index( a.czmc1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czmc1,
  52. a.czbm as czglbm,
  53. a.czmc as czglmc
  54. FROM
  55. ( SELECT zdbm,zdmc,czbm,czmc, substring_index( czbm, '+', - 1 ) AS czbm1,substring_index( czmc, '+', -1 ) AS czmc1 FROM dip1_ys where length(czbm)-length(replace(czbm,'+',''))=3) a
  56. JOIN mysql.help_topic b ON b.help_topic_id < (
  57. length( a.czbm1 ) - length( REPLACE ( a.czbm1, '/', '' ) ) + 1
  58. )) t4
  59. where t1.czbm1<>t2.czbm1<>t3.czbm1<>t4.czbm1
  60. and t1.zdbm=t2.zdbm
  61. and t2.zdbm=t3.zdbm
  62. and t1.czbm=t2.czbm
  63. and t2.czbm=t3.czbm
  64. and t3.czbm=t4.czbm
  65. order by zdbm,czbm

对四个加号进行比较

  1. DELETE from dip1_ys a where length(czbm)-length(replace(czbm,'+',''))=3
  2. -- A+B+C+D+F 2166
  3. INSERT INTO dip1_cf
  4. select t1.zdbm,t1.zdmc,CONCAT_WS('+',t1.czbm1,t2.czbm1,t3.czbm1,t4.czbm1,t5.czbm1) as czbm,CONCAT_WS('+',t1.czmc1,t2.czmc1,t1.czmc1,t4.czmc1,t5.czmc1) as czmc,t1.czbm as czglbm , t1.czmc as czglmc, 5 from
  5. (SELECT
  6. a.zdbm,
  7. a.zdmc,
  8. a.czbm,
  9. a.czmc,
  10. substring_index( substring_index( a.czbm1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czbm1,
  11. substring_index( substring_index( a.czmc1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czmc1,
  12. a.czbm as czglbm,
  13. a.czmc as czglmc
  14. FROM
  15. ( SELECT zdbm,zdmc,czbm,czmc, substring_index( czbm, '+', 1 ) AS czbm1,substring_index( czmc, '+', 1 ) AS czmc1 FROM dip1_ys where length(czbm)-length(replace(czbm,'+',''))=4) a
  16. JOIN mysql.help_topic b ON b.help_topic_id < (
  17. length( a.czbm1 ) - length( REPLACE ( a.czbm1, '/', '' ) ) + 1
  18. )) t1,
  19. (SELECT
  20. a.zdbm,
  21. a.zdmc,
  22. a.czbm,
  23. a.czmc,
  24. substring_index( substring_index( a.czbm1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czbm1,
  25. substring_index( substring_index( a.czmc1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czmc1,
  26. a.czbm as czglbm,
  27. a.czmc as czglmc
  28. FROM
  29. ( SELECT zdbm,zdmc, czbm,czmc, substring_index(substring_index( czbm, '+', 2 ),'+',-1 )AS czbm1,substring_index(substring_index( czmc, '+', 2 ),'+',-1 )AS czmc1 FROM dip1_ys where length(czbm)-length(replace(czbm,'+',''))=4) a
  30. JOIN mysql.help_topic b ON b.help_topic_id < (
  31. length( a.czbm1 ) - length( REPLACE ( a.czbm1, '/', '' ) ) + 1
  32. )) t2,
  33. (SELECT
  34. a.zdbm,
  35. a.zdmc,
  36. a.czbm,
  37. a.czmc,
  38. substring_index( substring_index( a.czbm1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czbm1,
  39. substring_index( substring_index( a.czmc1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czmc1,
  40. a.czbm as czglbm,
  41. a.czmc as czglmc
  42. FROM
  43. ( SELECT zdbm,zdmc,czbm,czmc, substring_index(substring_index( czbm, '+', 3 ),'+',- 1 )AS czbm1,substring_index(substring_index( czmc, '+', 2 ),'+',-1 )AS czmc1 FROM dip1_ys where length(czbm)-length(replace(czbm,'+',''))=4) a
  44. JOIN mysql.help_topic b ON b.help_topic_id < (
  45. length( a.czbm1 ) - length( REPLACE ( a.czbm1, '/', '' ) ) + 1
  46. )) t3,
  47. (SELECT
  48. a.zdbm,
  49. a.zdmc,
  50. a.czbm,
  51. a.czmc,
  52. substring_index( substring_index( a.czbm1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czbm1,
  53. substring_index( substring_index( a.czmc1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czmc1,
  54. a.czbm as czglbm,
  55. a.czmc as czglmc
  56. FROM
  57. ( SELECT zdbm,zdmc,czbm,czmc, substring_index(substring_index( czbm, '+', 4 ),'+',- 1 )AS czbm1,substring_index(substring_index( czmc, '+', 2 ),'+',-1 )AS czmc1 FROM dip1_ys where length(czbm)-length(replace(czbm,'+',''))=4) a
  58. JOIN mysql.help_topic b ON b.help_topic_id < (
  59. length( a.czbm1 ) - length( REPLACE ( a.czbm1, '/', '' ) ) + 1
  60. )) t4,
  61. (SELECT
  62. a.zdbm,
  63. a.zdmc,
  64. a.czbm,
  65. a.czmc,
  66. substring_index( substring_index( a.czbm1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czbm1,
  67. substring_index( substring_index( a.czmc1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czmc1,
  68. a.czbm as czglbm,
  69. a.czmc as czglmc
  70. FROM
  71. ( SELECT zdbm,zdmc,czbm,czmc, substring_index( czbm, '+', - 1 ) AS czbm1,substring_index( czmc, '+', -1 ) AS czmc1 FROM dip1_ys where length(czbm)-length(replace(czbm,'+',''))=4) a
  72. JOIN mysql.help_topic b ON b.help_topic_id < (
  73. length( a.czbm1 ) - length( REPLACE ( a.czbm1, '/', '' ) ) + 1
  74. )) t5
  75. where t1.czbm1<>t2.czbm1<>t3.czbm1<>t4.czbm1<>t5.czbm1
  76. and t1.zdbm=t2.zdbm
  77. and t2.zdbm=t3.zdbm
  78. and t1.czbm=t2.czbm
  79. and t2.czbm=t3.czbm
  80. and t3.czbm=t4.czbm
  81. and t4.czbm=t5.czbm
  82. order by zdbm,czbm

删除操作

  1. DELETE from dip1_ys a where length(czbm)-length(replace(czbm,'+',''))=4

5个+号

  1. insert into dip1_cf
  2. select t1.zdbm,t1.zdmc,CONCAT_WS('+',t1.czbm1,t2.czbm1,t3.czbm1,t4.czbm1,t5.czbm1,t6.czbm1) as czbm,CONCAT_WS('+',t1.czmc1,t2.czmc1,t1.czmc1,t4.czmc1,t5.czmc1,t6.czmc1) as czmc,t1.czbm as czglbm , t1.czmc as czglmc, 5 from
  3. (SELECT
  4. a.zdbm,
  5. a.zdmc,
  6. a.czbm,
  7. a.czmc,
  8. substring_index( substring_index( a.czbm1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czbm1,
  9. substring_index( substring_index( a.czmc1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czmc1,
  10. a.czbm as czglbm,
  11. a.czmc as czglmc
  12. FROM
  13. ( SELECT zdbm,zdmc,czbm,czmc, substring_index( czbm, '+', 1 ) AS czbm1,substring_index( czmc, '+', 1 ) AS czmc1 FROM dip1_ys where length(czbm)-length(replace(czbm,'+',''))=5) a
  14. JOIN mysql.help_topic b ON b.help_topic_id < (
  15. length( a.czbm1 ) - length( REPLACE ( a.czbm1, '/', '' ) ) + 1
  16. )) t1,
  17. (SELECT
  18. a.zdbm,
  19. a.zdmc,
  20. a.czbm,
  21. a.czmc,
  22. substring_index( substring_index( a.czbm1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czbm1,
  23. substring_index( substring_index( a.czmc1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czmc1,
  24. a.czbm as czglbm,
  25. a.czmc as czglmc
  26. FROM
  27. ( SELECT zdbm,zdmc, czbm,czmc, substring_index(substring_index( czbm, '+', 2 ),'+',-1 )AS czbm1,substring_index(substring_index( czmc, '+', 2 ),'+',-1 )AS czmc1 FROM dip1_ys where length(czbm)-length(replace(czbm,'+',''))=5) a
  28. JOIN mysql.help_topic b ON b.help_topic_id < (
  29. length( a.czbm1 ) - length( REPLACE ( a.czbm1, '/', '' ) ) + 1
  30. )) t2,
  31. (SELECT
  32. a.zdbm,
  33. a.zdmc,
  34. a.czbm,
  35. a.czmc,
  36. substring_index( substring_index( a.czbm1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czbm1,
  37. substring_index( substring_index( a.czmc1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czmc1,
  38. a.czbm as czglbm,
  39. a.czmc as czglmc
  40. FROM
  41. ( SELECT zdbm,zdmc,czbm,czmc, substring_index(substring_index( czbm, '+', 3 ),'+',- 1 )AS czbm1,substring_index(substring_index( czmc, '+', 2 ),'+',-1 )AS czmc1 FROM dip1_ys where length(czbm)-length(replace(czbm,'+',''))=5) a
  42. JOIN mysql.help_topic b ON b.help_topic_id < (
  43. length( a.czbm1 ) - length( REPLACE ( a.czbm1, '/', '' ) ) + 1
  44. )) t3,
  45. (SELECT
  46. a.zdbm,
  47. a.zdmc,
  48. a.czbm,
  49. a.czmc,
  50. substring_index( substring_index( a.czbm1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czbm1,
  51. substring_index( substring_index( a.czmc1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czmc1,
  52. a.czbm as czglbm,
  53. a.czmc as czglmc
  54. FROM
  55. ( SELECT zdbm,zdmc,czbm,czmc, substring_index(substring_index( czbm, '+', 4 ),'+',- 1 )AS czbm1,substring_index(substring_index( czmc, '+', 2 ),'+',-1 )AS czmc1 FROM dip1_ys where length(czbm)-length(replace(czbm,'+',''))=5) a
  56. JOIN mysql.help_topic b ON b.help_topic_id < (
  57. length( a.czbm1 ) - length( REPLACE ( a.czbm1, '/', '' ) ) + 1
  58. )) t4,
  59. (SELECT
  60. a.zdbm,
  61. a.zdmc,
  62. a.czbm,
  63. a.czmc,
  64. substring_index( substring_index( a.czbm1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czbm1,
  65. substring_index( substring_index( a.czmc1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czmc1,
  66. a.czbm as czglbm,
  67. a.czmc as czglmc
  68. FROM
  69. ( SELECT zdbm,zdmc,czbm,czmc, substring_index(substring_index( czbm, '+', 5 ),'+',- 1 )AS czbm1,substring_index(substring_index( czmc, '+', 2 ),'+',-1 )AS czmc1 FROM dip1_ys where length(czbm)-length(replace(czbm,'+',''))=5) a
  70. JOIN mysql.help_topic b ON b.help_topic_id < (
  71. length( a.czbm1 ) - length( REPLACE ( a.czbm1, '/', '' ) ) + 1
  72. )) t5,
  73. (SELECT
  74. a.zdbm,
  75. a.zdmc,
  76. a.czbm,
  77. a.czmc,
  78. substring_index( substring_index( a.czbm1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czbm1,
  79. substring_index( substring_index( a.czmc1, '/', b.help_topic_id + 1 ), '/',- 1 ) AS czmc1,
  80. a.czbm as czglbm,
  81. a.czmc as czglmc
  82. FROM
  83. ( SELECT zdbm,zdmc,czbm,czmc, substring_index( czbm, '+', - 1 ) AS czbm1,substring_index( czmc, '+', -1 ) AS czmc1 FROM dip1_ys where length(czbm)-length(replace(czbm,'+',''))=5) a
  84. JOIN mysql.help_topic b ON b.help_topic_id < (
  85. length( a.czbm1 ) - length( REPLACE ( a.czbm1, '/', '' ) ) + 1
  86. )) t6
  87. where t1.czbm1<>t2.czbm1<>t3.czbm1<>t4.czbm1<>t5.czbm1<>t5.czbm1
  88. and t1.zdbm=t2.zdbm
  89. and t2.zdbm=t3.zdbm
  90. and t1.czbm=t2.czbm
  91. and t2.czbm=t3.czbm
  92. and t3.czbm=t4.czbm
  93. and t4.czbm=t5.czbm
  94. and t5.czbm=t6.czbm
  95. order by zdbm,czbm

添加完成之后删除

  1. DELETE from dip1_ys a where length(czbm)-length(replace(czbm,'+',''))=5

将拆分出来的数据存到test表中,并用concai_ws语句诊断编码使用加号与操作编码拼接起来插入到test语句中对该语句进行去重操作,操作完成之后接下列语句

  1. insert into dip1_zc
  2. SELECT distinct(test1),zdbm,
  3. zdmc,
  4. czbm,
  5. czmc,
  6. czglbm,
  7. czglmc,
  8. cfbz from
  9. test

-- 对包含+号数据进行人工拆分

  1. insert into dip1_zctz
  2. select t.zdbm,t.zdmc,t.czglbm,t.czglmc,GROUP_CONCAT(distinct t.czbm1 order by czbm1 separator '+' ) as czbm,GROUP_CONCAT(distinct t.czmc1 order by czbm1 separator '+') as czmc,'暂定','暂定',t.cfbz
  3. from
  4. (SELECT zdbm,czbm,zdmc,czmc,czglbm,czglmc,
  5. substring_index( substring_index( a.czbm, '+', b.help_topic_id + 1 ), '+',- 1 ) AS czbm1,
  6. substring_index( substring_index( a.czmc, '+', b.help_topic_id + 1 ), '+',- 1 ) AS czmc1,
  7. cfbz
  8. FROM dip1_zc a
  9. JOIN mysql.help_topic b ON b.help_topic_id < (length( a.czbm) - length( REPLACE ( a.czbm, '+', '' ) ) + 1 )
  10. where cfbz >= 3
  11. ) t
  12. group by t.zdbm,t.czbm ;

-- 对不包含+号数据进行转存

  1. insert into dip1_zctz
  2. select t.zdbm,t.zdmc,t.czglbm,t.czglmc,t.czbm,t.czmc,'暂定','暂定',t.cfbz from dip1_zc t where cfbz<=2;

-- 病种组合编码 根据拆分标志 进行更新

  1. UPDATE dip1_zctz a
  2. set a.bzzhbm = CONCAT_WS(':',a.zdbm,'n(y)'),
  3. a.bzzhmc = CONCAT_WS(':',a.zdmc,'保守治疗'),
  4. a.cfbz = CONCAT_WS(':','0','操作编码为空')
  5. where cfbz = 0;
  1. UPDATE dip1_zctz
  2. set bzzhbm = CONCAT_WS(':',zdbm,czbm),
  3. bzzhmc = CONCAT_WS(':',zdmc,czmc)
  4. where cfbz = '1';
  1. UPDATE dip1_zctz
  2. set bzzhbm = CONCAT_WS(':',zdbm,czbm),
  3. bzzhmc = CONCAT_WS(':',zdmc,czmc)
  4. where cfbz = '2';
  1. UPDATE dip1_zctz
  2. set bzzhbm = CONCAT_WS(':',zdbm,czbm),
  3. bzzhmc = CONCAT_WS(':',zdmc,czmc)
  4. where cfbz = '3';
  1. UPDATE dip1_zctz
  2. set bzzhbm = CONCAT_WS(':',zdbm,czbm),
  3. bzzhmc = CONCAT_WS(':',zdmc,czmc)
  4. where cfbz = '4';
  1. UPDATE dip1_zctz
  2. set bzzhbm = CONCAT_WS(':',zdbm,czbm),
  3. bzzhmc = CONCAT_WS(':',zdmc,czmc)
  4. where cfbz = '5';
  1. UPDATE dip1_zctz
  2. set bzzhbm = CONCAT_WS(':',zdbm,czbm),
  3. bzzhmc = CONCAT_WS(':',zdmc,czmc)
  4. where cfbz = '6';
  1. UPDATE dip1_zctz
  2. set bzzhbm = CONCAT_WS(':',zdbm,czbm),
  3. bzzhmc = CONCAT_WS(':',zdmc,czmc)
  4. where cfbz = '7';
  1. UPDATE dip1_zctz a
  2. set a.cfbz = CONCAT_WS(':','1','操作编码不包含/')
  3. where a.cfbz = '1';
  1. UPDATE dip1_zctz a
  2. set a.cfbz = CONCAT_WS(':','2','操作编码只包含/')
  3. where a.cfbz = '2';
  1. UPDATE dip1_zctz a
  2. set a.cfbz = CONCAT_WS(':','3','操作编码包含一个+')
  3. where a.cfbz = '3';
  1. UPDATE dip1_zctz a
  2. set a.cfbz = CONCAT_WS(':','4','操作编码包含两个+')
  3. where a.cfbz = '4';
  1. UPDATE dip1_zctz a
  2. set a.cfbz = CONCAT_WS(':','5','操作编码包含三个+')
  3. where a.cfbz = '5';
  1. UPDATE dip1_zctz a
  2. set a.cfbz = CONCAT_WS(':','6','操作编码包含四个+')
  3. where a.cfbz = '6';
  1. UPDATE dip1_zctz a
  2. set a.cfbz = CONCAT_WS(':','7','操作编码包含五个+')
  3. where a.cfbz = '7';
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注