update-cp-location.sql 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. CREATE TEMPORARY TABLE temp_table AS
  2. SELECT s.num,c.new_num,e.location from t_scene_plus s LEFT JOIN t_scene_plus_ext e on s.id = e.plus_id
  3. LEFT JOIN t_scene_copy_log c on c.old_num = s.num
  4. WHERE s.rec_status = 'A' and c.id is not null and location is not null;
  5. SELECT location,count(1) from temp_table GROUP BY location;
  6. UPDATE t_scene_plus_ext set location = 1 WHERE location is null and plus_id in (
  7. SELECT id FROM t_scene_plus WHERE num in
  8. (SELECT new_num from temp_table WHERE location = 1)
  9. );
  10. UPDATE t_scene_plus_ext set location = 3 WHERE location is null and plus_id in (
  11. SELECT id FROM t_scene_plus WHERE num in
  12. (SELECT new_num from temp_table WHERE location = 3)
  13. );
  14. UPDATE t_scene_plus_ext set location = 4 WHERE location is null and plus_id in (
  15. SELECT id FROM t_scene_plus WHERE num in
  16. (SELECT new_num from temp_table WHERE location = 4)
  17. );
  18. UPDATE t_scene_plus_ext set location = 5 WHERE location is null and plus_id in (
  19. SELECT id FROM t_scene_plus WHERE num in
  20. (SELECT new_num from temp_table WHERE location = 5)
  21. );
  22. UPDATE t_scene_plus_ext set location = 6 WHERE location is null and plus_id in (
  23. SELECT id FROM t_scene_plus WHERE num in
  24. (SELECT new_num from temp_table WHERE location = 6)
  25. );
  26. DROP TABLE IF EXISTS temp_table;