DROP PROCEDURE IF EXISTS kysi_olemi_votmesonad; DELIMITER // CREATE PROCEDURE kysi_olemi_votmesonad(IN kood VARCHAR(50)) BEGIN DECLARE kood1 VARCHAR(50); DECLARE kokku INT; DECLARE finished INT DEFAULT 0; DECLARE cur1 CURSOR FOR SELECT teksti_kood FROM olemid_lausesonad WHERE olemi_kood=kood GROUP BY teksti_kood; DECLARE CONTINUE HANDLER FOR NOT FOUND SET finished = 1; CREATE TEMPORARY TABLE if not exists temp_lemmad(lyhilemma VARCHAR(50), kogus INT); DELETE FROM temp_lemmad; OPEN cur1; REPEAT FETCH cur1 INTO kood1; INSERT INTO temp_lemmad SELECT lyhilemma, kogus FROM tekstilemmad WHERE tekstikood=kood1; UNTIL NOT finished END REPEAT; SELECT lyhilemma, votmesus FROM ( SELECT t1.lyhilemma, sosakaal/(korpuselemmad.kogus/932057062) as votmesus FROM (SELECT lyhilemma, sum(kogus)/(SELECT SUM(kogus) FROM temp_lemmad) AS sosakaal FROM temp_lemmad GROUP BY lyhilemma HAVING sum(kogus)>2) t1 JOIN korpuselemmad ON t1.lyhilemma=korpuselemmad.lemma AND korpus='yhendkorpus') as t2 WHERE votmesus>3 ORDER BY votmesus DESC limit 75; END// DELIMITER ; call kysi_olemi_votmesonad('gunnar_graps_per'); MariaDB [errdata]> call kysi_olemi_votmesonad('arvo_pärt_per'); +---------------+----------------+ | lyhilemma | votmesus | +---------------+----------------+ | mozart | 71428.57142857 | | niukne | 14388.48920863 | | nihuke | 5989.58333333 | | karikatuur | 1028.54204166 | | kammermuusika | 985.70724495 | | programmiline | 515.75931232 | | tantsumuusika | 282.84098052 | | puht | 235.60209424 | | sümfoonia | 230.98498598 | | ballett | 173.76194613 | | pala | 99.98823668 | | niisugune | 93.65383758 | | graafika | 75.32182964 | | paralleel | 72.46376812 | | nõrkus | 57.90387956 | | muusika | 56.25204404 | | maalima | 52.38649593 | | ooper | 48.67232708 | | nauding | 47.96790511 | | muusikaline | 37.87559970 | | küllaltki | 37.74102793 | | konkreetselt | 33.38155113 | | vahest | 32.81726574 | | raadio | 27.69947697 | | helilooja | 25.55874251 | | pill | 20.98880597 | | plaat | 20.26198750 | | kontsert | 19.61183650 | | mingisugune | 19.11381407 | | sellepärast | 18.77612330 | | kasvõi | 18.69059062 | | näiteks | 15.45195162 | | vaev | 15.31500174 | | laulma | 15.20202404 | | emotsioon | 15.10280696 | | niimoodi | 15.01009770 | | kuulama | 14.24782950 | | noorem | 13.94152165 | | kunst | 12.73862168 | | meeldiv | 12.07013848 | | võib-olla | 11.42549903 | | ükskõik | 11.37857793 | | jah | 11.06397007 | | igati | 10.48169198 | | kuulma | 9.53320184 | | noh | 8.89586181 | | konkreetne | 8.66636953 | | mõjuma | 8.05239425 | | külastama | 7.58150114 | | määr | 7.44361462 | | vend | 7.09242214 | | kõrvale | 6.83366110 | | laul | 6.46207350 | | saade | 6.27365691 | | vahe | 5.61130014 | | seal | 5.52083450 | | värv | 5.47574441 | | juhatus | 5.25443124 | | tavaline | 5.18701549 | | sattuma | 5.05138638 | | kõrval | 5.04951328 | | seetõttu | 4.83848113 | | järel | 4.76044388 | | mingi | 4.72435572 | | eesti | 4.69075676 | | meeldima | 4.56489595 | | muidugi | 4.39068297 | | tõesti | 4.35048772 | | maa | 4.28705084 | | siiski | 4.27390469 | | nimetama | 4.23692907 | | ikka | 3.81699976 | | sees | 3.81000762 | | siin | 3.76231050 | | eks | 3.61142392 | +---------------+----------------+ 75 rows in set (0.184 sec) Query OK, 950 rows affected (0.186 sec)