同步BeautyType字段数据.sql
9.82 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
-- ============================================
-- 同步 F_BeautyType 字段数据
-- ============================================
-- 说明:从 lq_xmzl 表的 F_BeautyType 字段同步数据到其他相关表
--
-- 关联关系:
-- 1. lq_kd_pxmx: 通过 px 字段关联到 lq_xmzl.F_Id
-- 2. lq_kd_jksyj: 通过 F_kdpxid 关联到 lq_kd_pxmx,或通过 F_ItemId 直接关联到 lq_xmzl
-- 3. lq_kd_kjbsyj: 通过 F_kdpxid 关联到 lq_kd_pxmx,或通过 F_ItemId 直接关联到 lq_xmzl
-- 4. lq_hytk_mx: 通过 px 字段关联到 lq_xmzl.F_Id
-- 5. lq_hytk_jksyj: 通过 F_tkpxid 关联到 lq_hytk_mx,或通过 F_ItemId 直接关联到 lq_xmzl
-- 6. lq_hytk_kjbsyj: 通过 F_tkpxid 关联到 lq_hytk_mx,或通过 F_ItemId 直接关联到 lq_xmzl
-- 7. lq_xh_pxmx: 通过 px 字段关联到 lq_xmzl.F_Id
-- 8. lq_xh_jksyj: 通过 F_kdpxid 关联到 lq_xh_pxmx,或通过 F_ItemId 直接关联到 lq_xmzl
-- 9. lq_xh_kjbsyj: 通过 F_hkpxid 关联到 lq_xh_pxmx,或通过 F_ItemId 直接关联到 lq_xmzl
--
-- 注意事项:
-- - 优先使用 F_ItemId 直接关联(如果存在且有效)
-- - 如果 F_ItemId 为空,则通过关联表间接关联
-- - 只更新 F_BeautyType 为 NULL 或空字符串的记录
-- ============================================
-- 1. 同步 lq_kd_pxmx(开单品项明细表)
-- ============================================
UPDATE lq_kd_pxmx t1
INNER JOIN lq_xmzl t2 ON t1.px = t2.F_Id
SET t1.F_BeautyType = t2.F_BeautyType
WHERE t2.F_BeautyType IS NOT NULL
AND t2.F_BeautyType != ''
AND (t1.F_BeautyType IS NULL OR t1.F_BeautyType = '');
-- ============================================
-- 2. 同步 lq_kd_jksyj(开单健康师业绩表)
-- ============================================
-- 方式1:通过 F_ItemId 直接关联(优先)
UPDATE lq_kd_jksyj t1
INNER JOIN lq_xmzl t2 ON t1.F_ItemId = t2.F_Id
SET t1.F_BeautyType = t2.F_BeautyType
WHERE t2.F_BeautyType IS NOT NULL
AND t2.F_BeautyType != ''
AND t1.F_ItemId IS NOT NULL
AND t1.F_ItemId != ''
AND (t1.F_BeautyType IS NULL OR t1.F_BeautyType = '');
-- 方式2:通过 F_kdpxid 关联到 lq_kd_pxmx,再关联到 lq_xmzl
UPDATE lq_kd_jksyj t1
INNER JOIN lq_kd_pxmx t2 ON t1.F_kdpxid = t2.F_Id
INNER JOIN lq_xmzl t3 ON t2.px = t3.F_Id
SET t1.F_BeautyType = t3.F_BeautyType
WHERE t3.F_BeautyType IS NOT NULL
AND t3.F_BeautyType != ''
AND t1.F_kdpxid IS NOT NULL
AND t1.F_kdpxid != ''
AND (t1.F_ItemId IS NULL OR t1.F_ItemId = '')
AND (t1.F_BeautyType IS NULL OR t1.F_BeautyType = '');
-- ============================================
-- 3. 同步 lq_kd_kjbsyj(开单科技部老师业绩表)
-- ============================================
-- 方式1:通过 F_ItemId 直接关联(优先)
UPDATE lq_kd_kjbsyj t1
INNER JOIN lq_xmzl t2 ON t1.F_ItemId = t2.F_Id
SET t1.F_BeautyType = t2.F_BeautyType
WHERE t2.F_BeautyType IS NOT NULL
AND t2.F_BeautyType != ''
AND t1.F_ItemId IS NOT NULL
AND t1.F_ItemId != ''
AND (t1.F_BeautyType IS NULL OR t1.F_BeautyType = '');
-- 方式2:通过 F_kdpxid 关联到 lq_kd_pxmx,再关联到 lq_xmzl
UPDATE lq_kd_kjbsyj t1
INNER JOIN lq_kd_pxmx t2 ON t1.F_kdpxid = t2.F_Id
INNER JOIN lq_xmzl t3 ON t2.px = t3.F_Id
SET t1.F_BeautyType = t3.F_BeautyType
WHERE t3.F_BeautyType IS NOT NULL
AND t3.F_BeautyType != ''
AND t1.F_kdpxid IS NOT NULL
AND t1.F_kdpxid != ''
AND (t1.F_ItemId IS NULL OR t1.F_ItemId = '')
AND (t1.F_BeautyType IS NULL OR t1.F_BeautyType = '');
-- ============================================
-- 4. 同步 lq_hytk_mx(退卡品项明细表)
-- ============================================
UPDATE lq_hytk_mx t1
INNER JOIN lq_xmzl t2 ON t1.px = t2.F_Id
SET t1.F_BeautyType = t2.F_BeautyType
WHERE t2.F_BeautyType IS NOT NULL
AND t2.F_BeautyType != ''
AND (t1.F_BeautyType IS NULL OR t1.F_BeautyType = '');
-- ============================================
-- 5. 同步 lq_hytk_jksyj(退卡健康师业绩表)
-- ============================================
-- 方式1:通过 F_ItemId 直接关联(优先)
UPDATE lq_hytk_jksyj t1
INNER JOIN lq_xmzl t2 ON t1.F_ItemId = t2.F_Id
SET t1.F_BeautyType = t2.F_BeautyType
WHERE t2.F_BeautyType IS NOT NULL
AND t2.F_BeautyType != ''
AND t1.F_ItemId IS NOT NULL
AND t1.F_ItemId != ''
AND (t1.F_BeautyType IS NULL OR t1.F_BeautyType = '');
-- 方式2:通过 F_tkpxid 关联到 lq_hytk_mx,再关联到 lq_xmzl
UPDATE lq_hytk_jksyj t1
INNER JOIN lq_hytk_mx t2 ON t1.F_tkpxid = t2.F_Id
INNER JOIN lq_xmzl t3 ON t2.px = t3.F_Id
SET t1.F_BeautyType = t3.F_BeautyType
WHERE t3.F_BeautyType IS NOT NULL
AND t3.F_BeautyType != ''
AND t1.F_tkpxid IS NOT NULL
AND t1.F_tkpxid != ''
AND (t1.F_ItemId IS NULL OR t1.F_ItemId = '')
AND (t1.F_BeautyType IS NULL OR t1.F_BeautyType = '');
-- ============================================
-- 6. 同步 lq_hytk_kjbsyj(退卡科技部老师业绩表)
-- ============================================
-- 方式1:通过 F_ItemId 直接关联(优先)
UPDATE lq_hytk_kjbsyj t1
INNER JOIN lq_xmzl t2 ON t1.F_ItemId = t2.F_Id
SET t1.F_BeautyType = t2.F_BeautyType
WHERE t2.F_BeautyType IS NOT NULL
AND t2.F_BeautyType != ''
AND t1.F_ItemId IS NOT NULL
AND t1.F_ItemId != ''
AND (t1.F_BeautyType IS NULL OR t1.F_BeautyType = '');
-- 方式2:通过 F_tkpxid 关联到 lq_hytk_mx,再关联到 lq_xmzl
UPDATE lq_hytk_kjbsyj t1
INNER JOIN lq_hytk_mx t2 ON t1.F_tkpxid = t2.F_Id
INNER JOIN lq_xmzl t3 ON t2.px = t3.F_Id
SET t1.F_BeautyType = t3.F_BeautyType
WHERE t3.F_BeautyType IS NOT NULL
AND t3.F_BeautyType != ''
AND t1.F_tkpxid IS NOT NULL
AND t1.F_tkpxid != ''
AND (t1.F_ItemId IS NULL OR t1.F_ItemId = '')
AND (t1.F_BeautyType IS NULL OR t1.F_BeautyType = '');
-- ============================================
-- 7. 同步 lq_xh_pxmx(耗卡品项明细表)
-- ============================================
UPDATE lq_xh_pxmx t1
INNER JOIN lq_xmzl t2 ON t1.px = t2.F_Id
SET t1.F_BeautyType = t2.F_BeautyType
WHERE t2.F_BeautyType IS NOT NULL
AND t2.F_BeautyType != ''
AND (t1.F_BeautyType IS NULL OR t1.F_BeautyType = '');
-- ============================================
-- 8. 同步 lq_xh_jksyj(耗卡健康师业绩表)
-- ============================================
-- 方式1:通过 F_ItemId 直接关联(优先)
UPDATE lq_xh_jksyj t1
INNER JOIN lq_xmzl t2 ON t1.F_ItemId = t2.F_Id
SET t1.F_BeautyType = t2.F_BeautyType
WHERE t2.F_BeautyType IS NOT NULL
AND t2.F_BeautyType != ''
AND t1.F_ItemId IS NOT NULL
AND t1.F_ItemId != ''
AND (t1.F_BeautyType IS NULL OR t1.F_BeautyType = '');
-- 方式2:通过 F_kdpxid 关联到 lq_xh_pxmx,再关联到 lq_xmzl
UPDATE lq_xh_jksyj t1
INNER JOIN lq_xh_pxmx t2 ON t1.F_kdpxid = t2.F_Id
INNER JOIN lq_xmzl t3 ON t2.px = t3.F_Id
SET t1.F_BeautyType = t3.F_BeautyType
WHERE t3.F_BeautyType IS NOT NULL
AND t3.F_BeautyType != ''
AND t1.F_kdpxid IS NOT NULL
AND t1.F_kdpxid != ''
AND (t1.F_ItemId IS NULL OR t1.F_ItemId = '')
AND (t1.F_BeautyType IS NULL OR t1.F_BeautyType = '');
-- ============================================
-- 9. 同步 lq_xh_kjbsyj(耗卡科技部老师业绩表)
-- ============================================
-- 方式1:通过 F_ItemId 直接关联(优先)
UPDATE lq_xh_kjbsyj t1
INNER JOIN lq_xmzl t2 ON t1.F_ItemId = t2.F_Id
SET t1.F_BeautyType = t2.F_BeautyType
WHERE t2.F_BeautyType IS NOT NULL
AND t2.F_BeautyType != ''
AND t1.F_ItemId IS NOT NULL
AND t1.F_ItemId != ''
AND (t1.F_BeautyType IS NULL OR t1.F_BeautyType = '');
-- 方式2:通过 F_hkpxid 关联到 lq_xh_pxmx,再关联到 lq_xmzl
UPDATE lq_xh_kjbsyj t1
INNER JOIN lq_xh_pxmx t2 ON t1.F_hkpxid = t2.F_Id
INNER JOIN lq_xmzl t3 ON t2.px = t3.F_Id
SET t1.F_BeautyType = t3.F_BeautyType
WHERE t3.F_BeautyType IS NOT NULL
AND t3.F_BeautyType != ''
AND t1.F_hkpxid IS NOT NULL
AND t1.F_hkpxid != ''
AND (t1.F_ItemId IS NULL OR t1.F_ItemId = '')
AND (t1.F_BeautyType IS NULL OR t1.F_BeautyType = '');
-- ============================================
-- 10. 验证同步结果
-- ============================================
-- 查看各表同步的数据统计
-- SELECT
-- 'lq_kd_pxmx' AS table_name,
-- COUNT(*) AS total_count,
-- COUNT(F_BeautyType) AS beauty_type_count,
-- COUNT(*) - COUNT(F_BeautyType) AS null_count
-- FROM lq_kd_pxmx
-- UNION ALL
-- SELECT
-- 'lq_kd_jksyj' AS table_name,
-- COUNT(*) AS total_count,
-- COUNT(F_BeautyType) AS beauty_type_count,
-- COUNT(*) - COUNT(F_BeautyType) AS null_count
-- FROM lq_kd_jksyj
-- UNION ALL
-- SELECT
-- 'lq_kd_kjbsyj' AS table_name,
-- COUNT(*) AS total_count,
-- COUNT(F_BeautyType) AS beauty_type_count,
-- COUNT(*) - COUNT(F_BeautyType) AS null_count
-- FROM lq_kd_kjbsyj
-- UNION ALL
-- SELECT
-- 'lq_hytk_mx' AS table_name,
-- COUNT(*) AS total_count,
-- COUNT(F_BeautyType) AS beauty_type_count,
-- COUNT(*) - COUNT(F_BeautyType) AS null_count
-- FROM lq_hytk_mx
-- UNION ALL
-- SELECT
-- 'lq_hytk_jksyj' AS table_name,
-- COUNT(*) AS total_count,
-- COUNT(F_BeautyType) AS beauty_type_count,
-- COUNT(*) - COUNT(F_BeautyType) AS null_count
-- FROM lq_hytk_jksyj
-- UNION ALL
-- SELECT
-- 'lq_hytk_kjbsyj' AS table_name,
-- COUNT(*) AS total_count,
-- COUNT(F_BeautyType) AS beauty_type_count,
-- COUNT(*) - COUNT(F_BeautyType) AS null_count
-- FROM lq_hytk_kjbsyj
-- UNION ALL
-- SELECT
-- 'lq_xh_pxmx' AS table_name,
-- COUNT(*) AS total_count,
-- COUNT(F_BeautyType) AS beauty_type_count,
-- COUNT(*) - COUNT(F_BeautyType) AS null_count
-- FROM lq_xh_pxmx
-- UNION ALL
-- SELECT
-- 'lq_xh_jksyj' AS table_name,
-- COUNT(*) AS total_count,
-- COUNT(F_BeautyType) AS beauty_type_count,
-- COUNT(*) - COUNT(F_BeautyType) AS null_count
-- FROM lq_xh_jksyj
-- UNION ALL
-- SELECT
-- 'lq_xh_kjbsyj' AS table_name,
-- COUNT(*) AS total_count,
-- COUNT(F_BeautyType) AS beauty_type_count,
-- COUNT(*) - COUNT(F_BeautyType) AS null_count
-- FROM lq_xh_kjbsyj;