[Database] MySQL 연산 함수, 계산 함수, 수학 함수 (Mathematical Functions)


연산 함수, 계산 함수, 수학 함수 (Mathematical Functions)

ABS(), MOD(), SIGN()

ABS( x ), MOD( N, M ), SIGN( X )
SELECT ABS(-90), MOD( 7, 2 );

SELECT SIGN(-3), SIGN(3), SIGN(0);
  • 쿼리 결과

CEIL(), CEILING(), FLOOR(), ROUND(), ROUND(), TRUNCATE()

CEIL( X ), CEILING( X ), FLOOR( X ), ROUND( X ), ROUND( X, D ), TRUNCATE( X, D )
SELECT CEIL(33.3), CEILING(33.3), FLOOR(33.3);

SELECT ROUND(33.3), ROUND(33.5), ROUND(3.1415, 2);

SELECT TRUNCATE(123.12345678, 2), TRUNCATE(123.12345678, -2);
  • 쿼리 결과

RADIANS(), DEGREES(), PI()

RADIANS( X ), DEGREES( X ), PI( )
SELECT RADIANS(0), RADIANS(90), RADIANS(180), PI();

SELECT DEGREES(PI()/4), DEGREES(PI()/2), DEGREES(PI());
  • 쿼리 결과

SIN(), ASIN()

SIN( X ), ASIN( X )
SELECT SIN(0), SIN(RADIANS(90)), SIN(RADIANS(180));

SELECT DEGREES(ASIN(SIGN(PI()/2)))
  • 쿼리 결과

EXP(), LOG(), LN(), LOG2(), LOG10(), POW(), POWER()

EXP( X ), LOG( X ), LN( X ), LOG2( X ), LOG10( X ), POW( X, Y ), POWER( X, Y )
SELECT EXP(1), LOG(1), LOG(EXP(1)), LN(EXP(1));

SELECT LOG2(2), POW(2,4), LOG2(POW(2,4));

SELECT LOG10(10), POWER(10,3), LOG10(POWER(10,3));
  • 쿼리 결과

CONV()

CONV( N, from_base, to_base )
SELECT CONV('FF', 16, 10), CONV(10, 8, 2), CONV(10, 2, 8);
  • 쿼리 결과