MySQL函数
1.数学函数
SELECT ABS( - 8 ) ;
SELECT CEILING( 9.1 ) ;
SELECT FLOOR( 9.1 ) ;
SELECT RAND( ) ;
SELECT RAND( 10 ) ;
SELECT ROUND ( 5.6 , 2 ) ;
SELECT TRUNCATE ( 9.552 , 2 )
SELECT SIGN( 1000 ) ;
SELECT PI( ) ;
SELECT SQRT( 10 ) ;
SELECT MOD ( 5 , 2 ) ;
SELECT CEIL( 9.2 ) ;
SELECT POW( 2 , 3 ) ;
SELECT EXP( 3 ) ;
SELECT LOG10( 10 ) ;
SELECT RADIANS( 98 ) ;
SELECT DEGREES( PI( ) ) ;
2.字符串函数
SELECT CHAR_LENGTH( '好好学习' ) ;
SELECT CONCAT( '你好' , '啥' , '都是' ) ;
SELECT INSERT ( '几艘佛破哦' , 2 , 3 , '123' ) ;
SELECT INSERT ( '几艘佛破哦' , 10 , 3 , '123' ) ;
SELECT LOWER( 'IJFAFDA' ) ;
SELECT LCASE ( 'IJFAFDA' ) ;
SELECT UCASE ( 'dsjk' ) ;
SELECT UPPER( 'dsjk' ) ;
SELECT LEFT ( '开始就到了' , 3 ) ;
SELECT RIGHT ( '开始就到了' , 3 ) ;
SELECT REPLACE ( '开始就到了' , '开' , '我开' ) ;
SELECT SUBSTR( '开始就到了' , 1 , 3 ) ;
SELECT REVERSE( '开始就到了' ) ;
SELECT ASCII( '开始就到了' ) ;
SELECT CONCAT_WS( '*' , 'sfsfd' , '叫角度' )
SELECT FIND_IN_SET( "c" , "a,b,c,d,e" ) ;
SELECT FIELD( "c" , "a" , "b" , "c" , "d" , "e" ) ;
SELECT FORMAT ( 250500.5634 , 2 ) ;
SELECT LOCATE( 'st' , 'myteststring' ) ;
SELECT LTRIM( " RUNOOB " ) ;
SELECT RTRIM( " RUNOOB " ) ;
SELECT MID ( "RUNOOB" , 2 , 3 ) ;
SELECT POSITION( 'b' IN 'abc' ) ;
SELECT REPEAT ( '数据' , 2 ) ;
SELECT LPAD( 'abc' , 10 , 'dd' ) ;
SELECT RPAD( 'abc' , 10 , 'dd' ) ;
SELECT STRCMP( 'abdf' , 'ab' ) ;
SELECT SUBSTRING_INDEX( 'a*b' , '*' , 1 ) ;
SELECT SUBSTRING_INDEX( 'a*b' , '*' , - 1 ) ;
SELECT SUBSTRING_INDEX( SUBSTRING_INDEX( 'a*b*c*d*e' , '*' , 3 ) , '*' , - 1 ) ;
3.日期和时间函数
SELECT CURRENT_DATE ( ) ;
SELECT CURDATE( ) ;
SELECT NOW ( )
SELECT LOCALTIME( )
SELECT SYSDATE( )
SELECT YEAR ( NOW ( ) )
SELECT MONTH ( NOW ( ) )
SELECT DAYOFYEAR( NOW ( ) )
SELECT HOUR ( ( NOW ( ) ) )
SELECT MINUTE ( ( NOW ( ) ) )
SELECT SECOND ( NOW ( ) )
SELECT DATE_FORMAT( '2011-11-11 11:11:11' , '%Y-%m-%d %r' )
SELECT TIME_FORMAT( NOW ( ) , '%h:%i:%s' )
SELECT MAKEDATE( 2020 , 100 ) ;
SELECT DATEDIFF( NOW ( ) , 20200101180000 )
SELECT TIMESTAMPDIFF( DAY , NOW ( ) , 20200714 )
4.系统信息函数
SELECT VERSION( ) ;
SELECT USER ( ) ;
5.统计函数
SELECT COUNT ( studentno) FROM student
SELECT COUNT ( * ) FROM student;
SELECT COUNT ( 1 ) FROM student;
SELECT COUNT ( score) FROM result;
SELECT SUM ( score) AS 总和 FROM result;
SELECT AVG ( score) AS 平均分 FROM result;
SELECT MAX ( score) AS 最高分 FROM result;
SELECT MIN ( score) AS 最低分 FROM result;