Mysql Get Date Functions
Dec 31, 2017 - To know the last date of the current month,the LAST_DAY() function is combined. Function in MySQL return the current date in Date format.
MySQL built-in functions can be categorised into several groups. • Mathematical functions • Aggregate functions • String functions • Date and time functions • System Functions Here we show only a portion of all MySQL functions.
Torrent managing successful projects with prince 2016. To get the full list of available functions, consult the MySQL reference manual. Mathematical functions MySQL supports multiple mathematical functions. Mysql> SELECT RAND(); +-------------------+ RAND() +-------------------+ 0.29873 +-------------------+ The RAND() function returns a random number from the interval. Mysql> SELECT ABS(-3), PI(), SIN(0.5); +---------+----------+-------------------+ ABS(-3) PI() SIN(0.5) +---------+----------+-------------------+ 3 3.141593 0.04203 +---------+----------+-------------------+ The ABS() function returns the absolute value of a number. The PI() function gives the value of PI.
And the SIN() function computes the sine of an argument. Mysql> SELECT BIN(22), OCT(22), HEX(22); +---------+---------+---------+ BIN(22) OCT(22) HEX(22) +---------+---------+---------+ 10110 26 16 +---------+---------+---------+ We use functions to give binary, octal and hexadecimal representation of decimal 22. Mysql> SELECT CEIL(11.256), FLOOR(11.256), ROUND(11.256, 2); +--------------+---------------+------------------+ CEIL(11.256) FLOOR(11.256) ROUND(11.256, 2) +--------------+---------------+------------------+ 12 11 11.26 +--------------+---------------+------------------+ The CEIL() function rounds the value to the smallest following integer. The FLOOR() function rounds the value to the largest previous integer. The ROUND() returns a number rounded to a specified number of decimal places. Mysql> SELECT POW(3, 3), SQRT(9); +-----------+---------+ POW(3, 3) SQRT(9) +-----------+---------+ 27 3 +-----------+---------+ The power and the square root functions. Mysql> SELECT DEGREES(2*PI()); +-----------------+ DEGREES(2*PI()) +-----------------+ 360 +-----------------+ The DEGREES() function computes degrees from radians.
Aggregate functions Aggregate functions operate on sets of values. Mysql> SELECT * FROM Cars; +----+------------+--------+ Id Name Cost +----+------------+--------+ 1 Audi 52642 2 Mercedes 57127 3 Skoda 9000 4 Volvo 29000 5 Bentley 350000 6 Citroen 21000 7 Hummer 41400 8 Volkswagen 21600 +----+------------+--------+ We have the Cars table. Mysql> SELECT MIN(Cost), MAX(Cost), AVG(Cost) -> FROM Cars; +-----------+-----------+------------+ MIN(Cost) MAX(Cost) AVG(Cost) +-----------+-----------+------------+ 9000 350000 +-----------+-----------+------------+ We use the MIN(), MAX() and AVG() aggregate functions to compute the minimal price, maximal price and the average price of cars in the table. Mysql> SELECT SUM(Cost), COUNT(Id), STD(Cost), -> VARIANCE(Cost) FROM Cars; +-----------+-----------+-------------+------------------+ SUM(Cost) COUNT(Id) STD(Cost) VARIANCE(Cost) +-----------+-----------+-------------+------------------+ 581769 8 1 5.3594 +-----------+-----------+-------------+------------------+ We use the SUM() function to get the sum of all values in the Cost column. We count the number of cars in the table with the COUNT() function.