CREATE TABLE kajakad( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, mass INT, pikkus INT ); INSERT INTO kajakad (mass, pikkus) VALUES (90, 35); INSERT INTO kajakad (mass, pikkus) VALUES (99, 34); INSERT INTO kajakad (mass, pikkus) VALUES (93, 38); INSERT INTO kajakad (mass, pikkus) VALUES (60, 25); SELECT * FROM kajakad; SELECT * FROM kajakad WHERE mass>70; SELECT * FROM kajakad ORDER BY pikkus; SELECT * FROM kajakad ORDER BY mass DESC; SELECT * FROM kajakad WHERE mass>70 ORDER BY mass; SELECT mass, pikkus FROM kajakad; SELECT mass AS grammid, mass/28 AS untsid FROM kajakad; SELECT mass/pikkus as 'g/cm' FROM kajakad; SELECT COUNT(*) FROM kajakad; SELECT MAX(pikkus), MIN(mass), SUM(mass) FROM kajakad; Koosta tabel risttahukad tulpadega id, x, y, z Lisa mõned tahukad Väljasta andmed Väljasta andmed x-i pikkuste järjekorras Näita andmete juures põhja pindala Sorteeri andmed põhja pindala järgi kasvavalt Leia risttahukate ruumalad Leia risttahuka suurim ruumala mysql> SELECT * FROM kajakad; +----+------+--------+ | id | mass | pikkus | +----+------+--------+ | 1 | 90 | 35 | | 2 | 99 | 34 | | 3 | 93 | 38 | | 4 | 60 | 25 | +----+------+--------+ UPDATE kajakad SET mass=62 WHERE id=4; UPDATE kajakad SET mass=mass+1 WHERE id=4; UPDATE kajakad SET mass=mass+1 WHERE mass<100; DELETE FROM kajakad WHERE id=2; INSERT INTO kajakad (mass, pikkus) VALUES (10, 12); CREATE TABLE pallid( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, toon VARCHAR(15), x INT, y INT, r INT, dx INT, dy INT ); INSERT INTO pallid (toon, x, y, r, dx, dy) VALUES ("green", ROUND(RAND()*100), ROUND(RAND()*100), ROUND(RAND()*10), ROUND(RAND()*10)-5, ROUND(RAND()*10)-5); UPDATE pallid SET x=x+dx, y=y+dy; UPDATE pallid SET dx=ABS(dx) WHERE x<0; UPDATE pallid SET dx=-ABS(dx) WHERE x>=100; SELECT id, SQRT(x*x+y*y) AS kaugus FROM pallid; --Muuda siniseks pallid, mis on nullpunktist rohkem kui 50 ühiku kaugusel