CREATE TABLE ajatood( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, algus DATETIME, ots DATETIME, tasu DECIMAL(8, 2) ); INSERT INTO ajatood VALUES(DEFAULT, '2015-12-1 8:15', '2015-12-1 12:45', 25); INSERT INTO ajatood VALUES(DEFAULT, '2015-12-1 8:15', '2015-12-1 18:45', 45); INSERT INTO ajatood VALUES(DEFAULT, '2015-12-1 8:15', '2015-12-1 13:45', 15); SELECT *, tasu/TIMESTAMPDIFF(HOUR, algus, ots) AS tunnitasu FROM ajatood; SELECT *, tasu/TIMESTAMPDIFF(HOUR, algus, ots) AS tunnitasu FROM ajatood ORDER BY tunnitasu; SELECT * FROM ajatood WHERE HOUR(ots)>17; SELECT *, IF(HOUR(ots)>17, 'yletund', 'tavaline') AS aeg FROM ajatood; SELECT if(DAYOFWEEK(NOW())>1, DAYOFWEEK(NOW())-1, 7);