sql="\ncreate view seminar_body_za_cislo as\n select\n sr.cislo_body_id || '-' || sr.resitel_id as id,\n sr.cislo_body_id as cislo_id,\n sr.resitel_id as resitel_id,\n sum(sr.body) as body\n from seminar_reseni as sr\n group by sr.cislo_body_id, sr.resitel_id\n order by body desc;\n\ncreate view seminar_body_k_cislu as\n select\n akt_c.id || '-' || min_bzc.resitel_id as id,\n akt_c.id as cislo_id,\n min_bzc.resitel_id as resitel_id,\n max(akt_bzc.body) as body,\n sum(min_bzc.body) as body_celkem\n from ((seminar_cisla as akt_c\n inner join seminar_cisla as min_c on min_c.rocnik_id = akt_c.rocnik_id and akt_c.cislo >= min_c.cislo)\n inner join seminar_body_za_cislo as min_bzc on min_c.id = min_bzc.cislo_id)\n left outer join seminar_body_za_cislo as akt_bzc on akt_bzc.cislo_id = akt_c.id and akt_bzc.resitel_id = min_bzc.resitel_id \n group by akt_c.id, min_bzc.resitel_id, akt_bzc.resitel_id\n order by body_celkem desc;\n",
sql="\ncreate view seminar_body_za_cislo as\n select\n sr.cislo_body_id || '-' || sr.resitel_id as id,\n sr.cislo_body_id as cislo_id,\n sr.resitel_id as resitel_id,\n sum(sr.body) as body\n from seminar_reseni as sr\n group by sr.cislo_body_id, sr.resitel_id\n order by body desc;\n\ncreate view seminar_body_k_cislu as\n select\n akt_c.id || '-' || min_bzc.resitel_id as id,\n akt_c.id as cislo_id,\n min_bzc.resitel_id as resitel_id,\n max(akt_bzc.body) as body,\n sum(min_bzc.body) as body_celkem\n from ((seminar_cisla as akt_c\n inner join seminar_cisla as min_c on min_c.rocnik_id = akt_c.rocnik_id and akt_c.cislo >= min_c.cislo)\n inner join seminar_body_za_cislo as min_bzc on min_c.id = min_bzc.cislo_id)\n left outer join seminar_body_za_cislo as akt_bzc on akt_bzc.cislo_id = akt_c.id and akt_bzc.resitel_id = min_bzc.resitel_id \n group by akt_c.id, min_bzc.resitel_id, akt_bzc.resitel_id\n order by body_celkem desc;\n",
sql="\ndrop view seminar_body_k_cislu;\ndrop view seminar_body_za_cislo;\n\ncreate view seminar_body_za_cislo as\n select\n seminar_reseni.cislo_body_id || '-' || seminar_reseni.resitel_id as id,\n seminar_reseni.cislo_body_id as cislo_id,\n seminar_reseni.resitel_id as resitel_id,\n seminar_cisla.cislo as cislo,\n seminar_cisla.rocnik_id as rocnik_id,\n seminar_rocniky.rocnik as rocnik,\n seminar_cisla.verejna_vysledkovka as verejna_vysledkovka,\n sum(seminar_reseni.body) as body\n from\n seminar_reseni\n inner join seminar_cisla on seminar_reseni.cislo_body_id = seminar_cisla.id\n inner join seminar_rocniky on seminar_cisla.rocnik_id = seminar_rocniky.id\n group by seminar_reseni.cislo_body_id, seminar_reseni.resitel_id, seminar_cisla.cislo,\n seminar_cisla.rocnik_id, seminar_rocniky.rocnik, seminar_cisla.verejna_vysledkovka\n order by body desc;\n\ncreate view seminar_body_k_cislu_rocnik as\n select\n akt_body.id as id,\n akt_body.cislo_id as cislo_id,\n akt_body.resitel_id as resitel_id,\n akt_body.body as body,\n sum(min_body.body) as body_celkem\n from\n seminar_body_za_cislo as akt_body\n inner join seminar_body_za_cislo as min_body on\n (akt_body.resitel_id = min_body.resitel_id and\n (akt_body.rocnik = min_body.rocnik and akt_body.cislo >= min_body.cislo)\n )\n group by akt_body.id, akt_body.cislo_id, akt_body.resitel_id, akt_body.body\n order by body_celkem desc;\n\ncreate view seminar_body_k_cislu_odjakziva as\n select\n akt_body.id as id,\n akt_body.cislo_id as cislo_id,\n akt_body.resitel_id as resitel_id,\n akt_body.body as body,\n sum(min_body.body) as body_celkem\n from\n seminar_body_za_cislo as akt_body\n inner join seminar_body_za_cislo as min_body on\n (akt_body.resitel_id = min_body.resitel_id and\n ((akt_body.rocnik = min_body.rocnik and akt_body.cislo >= min_body.cislo) or\n (akt_body.rocnik < min_body.rocnik)\n )\n )\n group by akt_body.id, akt_body.cislo_id, akt_body.resitel_id, akt_body.body\n order by body_celkem desc;\n\n",
sql="\n\ndrop view seminar_body_k_cislu_rocnik;\ncreate view seminar_body_k_cislu_rocnik as\n select\n seminar_cisla.id || '-' || min_body.resitel_id as id,\n seminar_cisla.id as cislo_id,\n min_body.resitel_id as resitel_id,\n sum(min_body.body) as body\n from\n seminar_cisla\n inner join seminar_body_za_cislo as min_body on\n (min_body.rocnik_id = seminar_cisla.rocnik_id and seminar_cisla.cislo >= min_body.cislo)\n group by seminar_cisla.id, min_body.resitel_id\n order by body desc;\n\ndrop view seminar_body_k_cislu_odjakziva;\ncreate view seminar_body_k_cislu_odjakziva as\n select\n seminar_cisla.id || '-' || min_body.resitel_id as id,\n seminar_cisla.id as cislo_id,\n min_body.resitel_id as resitel_id,\n sum(min_body.body) as body\n from\n seminar_cisla\n inner join seminar_rocniky on\n (seminar_cisla.rocnik_id = seminar_rocniky.id)\n inner join seminar_body_za_cislo as min_body on\n (min_body.rocnik_id = seminar_cisla.rocnik_id and seminar_cisla.cislo >= min_body.cislo) or\n (min_body.rocnik < seminar_rocniky.rocnik)\n group by seminar_cisla.id, min_body.resitel_id\n order by body desc;\n",