Numeric Functions
Numeric Functions
-- CEILING() - Return the smallest integer value not less than the argument
-- FLOOR() - Return the largest integer value not greater than the argument
SELECT PI();
SELECT PI()+0.000000000000000000;
-- POW() - Return the argument raised to the specified power - synonym for POWER(X,Y)
SELECT POW(2,2);
SELECT POWER(8,-2);
SELECT SQRT(4);
SELECT SQRT(64);
SELECT SQRT(-256);
-- Table Column
SELECT CHAR(77,121,83,81,76);
SELECT CHAR(65);
-- -1 if the first argument is smaller than the second according to the current sort order
-- 1 if the first argument is larger than the second according to the current sort order
STRCMP('SQLAuthority', 'MySQLAuthority'),
STRCMP('SQLAuthority', 'SQLAuthority');
SELECT REVERSE('SQLAuthority');
-- Table Column
FROM sakila.actor;
Date time functions
SELECT NOW(),
DATE(NOW()),
TIME(NOW()),
YEAR(NOW()),
QUARTER(NOW()),
MONTH(NOW()),
WEEK(NOW()),
DAY(NOW()),
DAYNAME(NOW()),
HOUR(NOW()),
MINUTE(NOW()),
SECOND(NOW());
/*
Format Description
%c Month, numeric
%D Day of month with English suffix
%f Microseconds
%H Hour (00-23)
%h Hour (01-12)
%I Hour (01-12)
%k Hour (0-23)
%l Hour (1-12)
%M Month name
%p AM or PM
%S Seconds (00-59)
%s Seconds (00-59)
%V Week (01-53) where Sunday is the first day of week, used with %X
%v Week (01-53) where Monday is the first day of week, used with %x
%W Weekday name
%X Year of the week where Sunday is the first day of week, four digits, used with %V
%x Year of the week where Monday is the first day of week, four digits, used with %v
*/
-- http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html#function_addtime
-- Table Column
FROM sakila.rental;
Control flow functions
SET @Var = 1;
-- Example of IF functions
SELECT IF(1>2,2,3);
SELECT IF(1<2,'yes','no');
SELECT IFNULL(1,0);
SELECT IFNULL(NULL,0);
SELECT 1/0;
SELECT IFNULL(1/0,'Yes');
SELECT NULLIF(1,1);
SELECT NULLIF(5,2);
Cast functions
-- CAST() or CONVERT()
SELECT 1-2;
Information functions
Misc functionss