mysql> select * from ilmharkus limit 1; +-----------+-------------+----------+---------+---------+----------+---------+---------+------------+-------------+----------------+ | kuunumber | paevanumber | kellaaeg | sademed | niiskus | tempkesk | tempmin | tempmax | tuulesuund | tuulekiirus | tuulemaxkiirus | +-----------+-------------+----------+---------+---------+----------+---------+---------+------------+-------------+----------------+ | 1 | 1 | 00:00:00 | 0 | 86 | 4.4 | 4.4 | 4.5 | 221 | 5.6 | 10.2 | +-----------+-------------+----------+---------+---------+----------+---------+---------+------------+-------------+----------------+ 1 row in set (0.00 sec) -- Iga jaanuarikuu päeva kohta suurim ja vähim niiskusprotsent SELECT MIN(niiskus) FROM ilmharkus WHERE kuunumber=1 AND paevanumber=1; +--------------+ | MIN(niiskus) | +--------------+ | 84 | +--------------+ SELECT MIN(niiskus), MAX(niiskus) FROM ilmharkus WHERE kuunumber=1 AND paevanumber=1; +--------------+--------------+ | MIN(niiskus) | MAX(niiskus) | +--------------+--------------+ | 84 | 100 | +--------------+--------------+ SELECT paevanumber, MIN(niiskus), MAX(niiskus) FROM ilmharkus WHERE kuunumber=1 GROUP BY paevanumber; +-------------+--------------+--------------+ | paevanumber | MIN(niiskus) | MAX(niiskus) | +-------------+--------------+--------------+ | 1 | 84 | 100 | | 2 | 80 | 100 | | 3 | 88 | 96 | | 4 | 97 | 100 | | 5 | 95 | 100 | | 6 | 96 | 100 | | 7 | 93 | 100 | | 8 | 96 | 99 | | 9 | 98 | 100 | | 10 | 93 | 100 | | 11 | 95 | 100 | | 12 | 87 | 100 | | 13 | 83 | 95 | | 14 | 89 | 96 | | 15 | 81 | 96 | | 16 | 79 | 97 | | 17 | 84 | 98 | | 18 | 78 | 93 | | 19 | 79 | 96 | | 20 | 81 | 94 | | 21 | 73 | 92 | | 22 | 83 | 95 | | 23 | 73 | 91 | | 24 | 69 | 90 | | 25 | 80 | 90 | | 26 | 87 | 92 | | 27 | 75 | 89 | | 28 | 72 | 87 | | 29 | 60 | 78 | | 30 | 49 | 78 | | 31 | 46 | 89 | +-------------+--------------+--------------+ -- Väljasta vähimad niiskused nendel jaanuarikuu päevadel, kus maksimumniiskus oli 100% SELECT paevanumber, MIN(niiskus), MAX(niiskus) FROM ilmharkus WHERE kuunumber=1 GROUP BY paevanumber; SELECT paevanumber, MIN(niiskus) FROM ilmharkus WHERE kuunumber=1 GROUP BY paevanumber HAVING MAX(niiskus)=100; +-------------+--------------+ | paevanumber | MIN(niiskus) | +-------------+--------------+ | 1 | 84 | | 2 | 80 | | 4 | 97 | | 5 | 95 | | 6 | 96 | | 7 | 93 | | 9 | 98 | | 10 | 93 | | 11 | 95 | | 12 | 87 | +-------------+--------------+ SELECT paevanumber, v2him FROM (SELECT paevanumber, MIN(niiskus) AS v2him, MAX(niiskus) AS suurim FROM ilmharkus WHERE kuunumber=1 GROUP BY paevanumber) AS t1 WHERE suurim=100; +-------------+-------+ | paevanumber | v2him | +-------------+-------+ | 1 | 84 | | 2 | 80 | | 4 | 97 | | 5 | 95 | | 6 | 96 | | 7 | 93 | | 9 | 98 | | 10 | 93 | | 11 | 95 | | 12 | 87 | +-------------+-------+ -- Näidake suurim niiskus nendel jaanuarikuu päevadel, kus vähim niiskus on alla 85% SELECT paevanumber, MIN(niiskus), MAX(niiskus) FROM ilmharkus WHERE kuunumber=1 GROUP BY paevanumber HAVING MIN(niiskus)<85; Leia jaanuari vähim õhuniiskus tunnis sellisel päeval, kus päeva maksimumniiskus on olnud 100% SELECT MIN(v2him) FROM (SELECT paevanumber, MIN(niiskus) AS v2him, MAX(niiskus) AS suurim FROM ilmharkus WHERE kuunumber=1 GROUP BY paevanumber) AS t1 WHERE suurim=100; +------------+ | MIN(v2him) | +------------+ | 80 | +------------+ SELECT MIN(v2him) FROM (SELECT paevanumber, MIN(niiskus) AS v2him, MAX(niiskus) AS suurim FROM ilmharkus WHERE kuunumber=1 GROUP BY paevanumber HAVING suurim=100) AS t1; +------------+ | MIN(v2him) | +------------+ | 80 | +------------+ -- Näita iga kuu kohta vähim niiskus päevas, kus on olnud niiskuseks ka 100% SELECT kuunumber, MIN(v2him) FROM (SELECT kuunumber, paevanumber, MIN(niiskus) AS v2him, MAX(niiskus) AS suurim FROM ilmharkus WHERE kuunumber=1 GROUP BY paevanumber HAVING suurim=100) AS t1; +-----------+------------+ | kuunumber | MIN(v2him) | +-----------+------------+ | 1 | 80 | +-----------+------------+ SELECT kuunumber, MIN(v2him) FROM (SELECT kuunumber, paevanumber, MIN(niiskus) AS v2him, MAX(niiskus) AS suurim FROM ilmharkus WHERE kuunumber=1 GROUP BY paevanumber HAVING suurim=100) AS t1; SELECT kuunumber, paevanumber, MIN(niiskus) AS v2him, MAX(niiskus) AS suurim FROM ilmharkus GROUP BY kuunumber, paevanumber; +-----------+-------------+-------+--------+ | kuunumber | paevanumber | v2him | suurim | +-----------+-------------+-------+--------+ | 1 | 1 | 84 | 100 | | 1 | 2 | 80 | 100 | | 1 | 3 | 88 | 96 | | 1 | 4 | 97 | 100 | | 1 | 5 | 95 | 100 | | 1 | 6 | 96 | 100 | | 1 | 7 | 93 | 100 | | 1 | 8 | 96 | 99 | | 1 | 9 | 98 | 100 | | 1 | 10 | 93 | 100 | | 1 | 11 | 95 | 100 | | 1 | 12 | 87 | 100 | | 1 | 13 | 83 | 95 | | 1 | 14 | 89 | 96 | | 1 | 15 | 81 | 96 | | 1 | 16 | 79 | 97 | | 1 | 17 | 84 | 98 | | 1 | 18 | 78 | 93 | | 1 | 19 | 79 | 96 | | 1 | 20 | 81 | 94 | | 1 | 21 | 73 | 92 | | 1 | 22 | 83 | 95 | | 1 | 23 | 73 | 91 | | 1 | 24 | 69 | 90 | | 1 | 25 | 80 | 90 | | 1 | 26 | 87 | 92 | | 1 | 27 | 75 | 89 | | 1 | 28 | 72 | 87 | | 1 | 29 | 60 | 78 | | 1 | 30 | 49 | 78 | | 1 | 31 | 46 | 89 | | 2 | 1 | 66 | 93 | | 2 | 2 | 56 | 99 | | 2 | 3 | 99 | 100 | | 2 | 4 | 98 | 100 | | 2 | 5 | 87 | 98 | | 2 | 6 | 71 | 93 | | 2 | 7 | 94 | 100 | | 2 | 8 | 93 | 99 | | 2 | 9 | 75 | 100 | | 2 | 10 | 96 | 100 | | 2 | 11 | 100 | 100 | | 2 | 12 | 97 | 100 | | 2 | 13 | 91 | 100 | | 2 | 14 | 84 | 96 | | 2 | 15 | 84 | CREATE TABLE ilm_paevaminmax AS SELECT kuunumber, paevanumber, MIN(niiskus) AS v2him, MAX(niiskus) AS suurim FROM ilmharkus GROUP BY kuunumber, paevanumber; SELECT * FROM ilm_paevaminmax LIMIT 5; SELECT kuunumber, paevanumber, MIN(niiskus) AS v2him, MAX(niiskus) AS suurim FROM ilmharkus GROUP BY kuunumber, paevanumber HAVING MAX(niiskus)=100; -- Näita iga kuu kohta vähim niiskus päevas, kus on olnud niiskuseks ka 100% SELECT kuunumber, MIN(v2him) FROM (SELECT kuunumber, paevanumber, MIN(niiskus) AS v2him, MAX(niiskus) AS suurim FROM ilmharkus GROUP BY kuunumber, paevanumber HAVING MAX(niiskus)=100) AS t1 GROUP BY kuunumber; +-----------+------------+ | kuunumber | MIN(v2him) | +-----------+------------+ | 1 | 80 | | 2 | 75 | | 3 | 0 | | 4 | 48 | | 5 | 35 | | 6 | 48 | | 7 | 48 | | 8 | 47 | | 9 | 50 | | 10 | 45 | | 11 | 76 | +-----------+------------+ SELECT DISTINCT t2.kuunumber, vihmapaevavahim FROM ilmharkus AS t2 LEFT JOIN (SELECT kuunumber, MIN(v2him) AS vihmapaevavahim FROM (SELECT kuunumber, paevanumber, MIN(niiskus) AS v2him, MAX(niiskus) AS suurim FROM ilmharkus WHERE niiskus>0 GROUP BY kuunumber, paevanumber HAVING MAX(niiskus)=100) AS t1 GROUP BY kuunumber) AS t3 ON t2.kuunumber=t3.kuunumber; +-----------+-----------------+ | kuunumber | vihmapaevavahim | +-----------+-----------------+ | 1 | 80 | | 2 | 75 | | 3 | 47 | | 4 | 48 | | 5 | 35 | | 6 | 48 | | 7 | 48 | | 8 | 47 | | 9 | 50 | | 10 | 45 | | 11 | 76 | | 12 | NULL | +-----------+-----------------+ SET @a=3; SET @a=@a+1; SELECT @a; mysql> SET @a=3; Query OK, 0 rows affected (0.00 sec) mysql> SET @a=@a+1; Query OK, 0 rows affected (0.00 sec) mysql> SELECT @a; +------+ | @a | +------+ | 4 | +------+ 1 row in set (0.00 sec) SET @eesnimi="Juku"; SELECT @eesnimi; SET @keskniiskus=(SELECT AVG(niiskus) FROM ilmharkus); SELECT COUNT(*) FROM ilmharkus WHERE niiskus>@keskniiskus; SELECT @keskniiskus; mysql> SELECT COUNT(*) FROM ilmharkus WHERE niiskus>@keskniiskus; +----------+ | COUNT(*) | +----------+ | 5336 | +----------+ 1 row in set (0.01 sec) mysql> SELECT @keskniiskus; +--------------+ | @keskniiskus | +--------------+ | 82.241438356 | +--------------+ SET @kuu=4; SET @vihmatunde=(SELECT COUNT(*) FROM ilmharkus WHERE kuunumber=@kuu AND niiskus=100); SET @kokkutunde=(SELECT COUNT(*) FROM ilmharkus WHERE kuunumber=@kuu); SELECT 'vihmaprotsent ', 100*@vihmatunde/@kokkutunde; +----------------+-----------------------------+ | vihmaprotsent | 100*@vihmatunde/@kokkutunde | +----------------+-----------------------------+ | vihmaprotsent | 1.5278 | +----------------+-----------------------------+ SET @kuu=5; ... +----------------+-----------------------------+ | vihmaprotsent | 100*@vihmatunde/@kokkutunde | +----------------+-----------------------------+ | vihmaprotsent | 7.9301 | +----------------+-----------------------------+ -- Paigutage muutujasse etteantud kuu tundide arv, kus niiskus on alla 60% -- Muutke kuu numbrit eraldi muutujas, arvutage, kui palju on vastava kuu kuivade tundide (<60%) protsent SET @kuivitunde=(SELECT COUNT(*) FROM ilmharkus WHERE kuunumber=@kuu AND niiskus<60); SELECT @kuivitunde/@kokkutunde; +-------------------------+ | @kuivitunde/@kokkutunde | +-------------------------+ | 0.2218 | +-------------------------+ DELIMITER // CREATE PROCEDURE kellaaeg() BEGIN SELECT NOW(); END // DELIMITER ; CALL kellaaeg(); +---------------------+ | NOW() | +---------------------+ | 2016-11-10 10:58:45 | +---------------------+ 1 row in set (0.01 sec) DROP PROCEDURE IF EXISTS kellaaeg; DELIMITER // CREATE PROCEDURE kellaaeg() BEGIN SET @loendur=1; WHILE @loendur<=3 DO SELECT @loendur, NOW(); SET @loendur=@loendur+1; END WHILE; END // DELIMITER ; CALL kellaaeg(); mysql> CALL kellaaeg(); +----------+---------------------+ | @loendur | NOW() | +----------+---------------------+ | 1 | 2016-11-10 11:03:46 | +----------+---------------------+ 1 row in set (0.01 sec) +----------+---------------------+ | @loendur | NOW() | +----------+---------------------+ | 2 | 2016-11-10 11:03:46 | +----------+---------------------+ 1 row in set (0.01 sec) +----------+---------------------+ | @loendur | NOW() | +----------+---------------------+ | 3 | 2016-11-10 11:03:46 | +----------+---------------------+ 1 row in set (0.01 sec) DROP PROCEDURE IF EXISTS vihmkuus; DELIMITER // CREATE PROCEDURE vihmkuus() BEGIN SET @kuu=1; WHILE @kuu<=12 DO SET @vihmatunde=(SELECT COUNT(*) FROM ilmharkus WHERE kuunumber=@kuu AND niiskus=100); SET @kokkutunde=(SELECT COUNT(*) FROM ilmharkus WHERE kuunumber=@kuu); SELECT @kuu, 100*@vihmatunde/@kokkutunde; SET @kuu=@kuu+1; END WHILE; END // DELIMITER ; CALL vihmkuus();