作者 tangxvhui

更新脚本

  1 +-- 更新staff_assess
  2 +WITH t_staff_assess AS (
  3 + SELECT
  4 + *
  5 + FROM
  6 + staff_assess
  7 + WHERE
  8 + 1 = 1
  9 + AND cycle_id = 1653724699349225472
  10 + AND NOT EXISTS (
  11 + SELECT
  12 + *
  13 + FROM
  14 + staff_assess_content
  15 + WHERE
  16 + staff_assess_content.staff_assess_id = staff_assess.id))
  17 +UPDATE
  18 + staff_assess
  19 +SET
  20 + deleted_at = now()
  21 +WHERE
  22 + 1 = 1
  23 + AND staff_assess.id IN (
  24 + SELECT
  25 + id
  26 + FROM
  27 + t_staff_assess);
  28 +
  29 +-- 更新staff_assess
  30 +WITH t_staff_assess AS (
  31 + SELECT
  32 + row_number() OVER (PARTITION BY evaluation_project_id,
  33 + "types",
  34 + staff_assess.begin_time) AS row_id,
  35 + *
  36 + FROM
  37 + staff_assess
  38 + WHERE
  39 + 1 = 1
  40 + AND cycle_id = 1653724699349225472
  41 + AND NOT EXISTS (
  42 + SELECT
  43 + *
  44 + FROM
  45 + staff_assess_content
  46 + WHERE
  47 + staff_assess_content.staff_assess_id = staff_assess.id)
  48 +),
  49 +t_staff_assess_2 AS (
  50 + SELECT
  51 + *
  52 + FROM
  53 + t_staff_assess
  54 + WHERE
  55 + row_id = 1)
  56 +UPDATE
  57 + staff_assess
  58 +SET
  59 + deleted_at = NULL
  60 +WHERE
  61 + 1 = 1
  62 + AND cycle_id = 1653724699349225472
  63 + AND staff_assess.id IN (
  64 + SELECT
  65 + id
  66 + FROM
  67 + t_staff_assess_2);
  68 +
  69 +;
  70 +
  71 +UPDATE
  72 + staff_assess
  73 +SET
  74 + deleted_at = now()
  75 +WHERE
  76 + id IN (18404, 18458);
  77 +