create table footDatabase.saliu_sezonai_1 as
SELECT replace(p.page_title, '_', ' ') _page,
trim('=' from if(LOCATE('
|fed', tt.old_text)=0,' ',
substr(substr(tt.old_text,LOCATE('
|fed', tt.old_text)+6),1,
LOCATE('
', substr(tt.old_text,LOCATE('
|fed', tt.old_text)+6))-1))) fed,
trim('=' from if(LOCATE('
|sez', tt.old_text)=0,' ',
substr(substr(tt.old_text,LOCATE('
|sez', tt.old_text)+6),1,
LOCATE('
', substr(tt.old_text,LOCATE('
|sez', tt.old_text)+6))-1))) sez,
trim('=' from if(LOCATE('
|uef', tt.old_text)=0,' ',
substr(substr(tt.old_text,LOCATE('
|uef', tt.old_text)+6),1,
LOCATE('
', substr(tt.old_text,LOCATE('
|uef', tt.old_text)+6))-1))) uef,
trim('=' from if(LOCATE('
|tip', tt.old_text)=0,' ',
substr(substr(tt.old_text,LOCATE('
|tip', tt.old_text)+6),1,
LOCATE('
', substr(tt.old_text,LOCATE('
|tip', tt.old_text)+6))-1))) tip
FROM futbolas.`fut_templatelinks` t
left join futbolas.fut_page p on t.tl_from=p.page_id
left join futbolas.fut_revision r on p.page_latest=r.rev_id and p.page_id=r.rev_page
left join futbolas.fut_text tt on tt.old_id=r.rev_text_id
WHERE t.`tl_title` = 'Varsez'
and t.`tl_namespace` = 10
and p.page_namespace = 0;
create table saliu_sezonai_2
SELECT _page, fed, case when sez='' then uef else sez end sez, tip FROM `saliu_sezonai_1`;