2023-05-04_2.sql
2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
-- 更新staff_assess
WITH t_staff_assess AS (
SELECT
*
FROM
staff_assess
WHERE
1 = 1
AND cycle_id = 1653724699349225472
AND NOT EXISTS (
SELECT
*
FROM
staff_assess_content
WHERE
staff_assess_content.staff_assess_id = staff_assess.id))
UPDATE
staff_assess
SET
deleted_at = now()
WHERE
1 = 1
AND staff_assess.id IN (
SELECT
id
FROM
t_staff_assess);
-- 更新staff_assess
WITH t_staff_assess AS (
SELECT
row_number() OVER (PARTITION BY evaluation_project_id,
"types",
staff_assess.begin_time) AS row_id,
*
FROM
staff_assess
WHERE
1 = 1
AND cycle_id = 1653724699349225472
AND NOT EXISTS (
SELECT
*
FROM
staff_assess_content
WHERE
staff_assess_content.staff_assess_id = staff_assess.id)
),
t_staff_assess_2 AS (
SELECT
*
FROM
t_staff_assess
WHERE
row_id = 1)
UPDATE
staff_assess
SET
deleted_at = NULL
WHERE
1 = 1
AND cycle_id = 1653724699349225472
AND staff_assess.id IN (
SELECT
id
FROM
t_staff_assess_2);
;
UPDATE
staff_assess
SET
deleted_at = now()
WHERE
id IN (18404, 18458);
--
WITH t1 AS (
SELECT
summary_evaluation_value.evaluation_item_id,
summary_evaluation_value.value,
summary_evaluation_value.id AS value_id,
summary_evaluation_value.score,
summary_evaluation.company_id
FROM
summary_evaluation_value
JOIN summary_evaluation ON summary_evaluation_value.summary_evaluation_id = summary_evaluation.id
WHERE
summary_evaluation_value.value = summary_evaluation_value.score
AND summary_evaluation."types" = 1
ORDER BY
summary_evaluation_value.created_at
)
SELECT
t1.value_id,
cast(evaluation_item_used.weight AS float) AS weight,
cast(t1.value AS float) AS value,
cast(t1.value AS float) * cast(evaluation_item_used.weight AS float) AS real_value
FROM
evaluation_item_used
JOIN t1 ON t1.evaluation_item_id = evaluation_item_used.id