Skip to content

Instantly share code, notes, and snippets.

@avkosme
Created May 15, 2018 14:11
Show Gist options
  • Save avkosme/fa42fac3384cba4d9b62c273a2cb4345 to your computer and use it in GitHub Desktop.
Save avkosme/fa42fac3384cba4d9b62c273a2cb4345 to your computer and use it in GitHub Desktop.
sql procedure
drop table if exists appFilesX;
create table appFilesX like app_files;
drop function if exists allUpdate;
create function allUpdate(pathGroup varchar(255) charset utf8 collate utf8_unicode_ci, fileId INT) returns int
begin
insert into appFilesX select * from app_files
where file_id is null and path=pathGroup;
update app_files set file_id = fileId
where file_id is null and path=pathGroup;
return 0;
end;
drop table if exists appFilesPath;
create table appFilesPath as
SELECT path, min(file_id) as u_file_id
FROM app_files
GROUP BY path
HAVING count(path) > 1 and u_file_id is not null;
select sum(x)
from (select *, allUpdate(path, u_file_id) as x from appFilesPath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment