mysql> select substring("xiaosong",2); +-------------------------+ | substring("xiaosong",2) | +-------------------------+ | iaosong | +-------------------------+ 1 row in set (0.00 sec) mysql> select substring("xiaosong",2,4); +---------------------------+ | substring("xiaosong",2,4) | +---------------------------+ | iaos | +---------------------------+ 1 row in set (0.00 sec) mysql> select strcmp("11","bb"); +-------------------+ | strcmp("11","bb") | +-------------------+ | -1 | +-------------------+ 1 row in set (0.00 sec) mysql> select strcmp("bb","bb"); +-------------------+ | strcmp("bb","bb") | +-------------------+ | 0 | +-------------------+ 1 row in set (0.00 sec) mysql> select strcmp("ba","bb"); +-------------------+ | strcmp("ba","bb") | +-------------------+ | -1 | +-------------------+ 1 row in set (0.00 sec) mysql> select strcmp("11",11); +-----------------+ | strcmp("11",11) | +-----------------+ | 0 | +-----------------+ 1 row in set (0.00 sec) mysql> select strcmp(11,11); +---------------+ | strcmp(11,11) | +---------------+ | 0 | +---------------+ 1 row in set (0.00 sec) mysql> select mysql 英文字符串, -> length('mysql') mysql的长度; ERROR 1054 (42S22): Unknown column 'mysql' in 'field list' mysql> select 'mysql' 英文字符串, -> length('mysql') mysql字符串的长度; +------------+-------------------+ | 英文字符串 | mysql字符串的长度 | +------------+-------------------+ | mysql | 5 | +------------+-------------------+ 1 row in set (0.00 sec) mysql> select find_in_set("33","1,3,4,55,44"); +---------------------------------+ | find_in_set("33","1,3,4,55,44") | +---------------------------------+ | 0 | +---------------------------------+ 1 row in set (0.00 sec) mysql> select find_in_set("33","1,3,33,4,55,44"); +------------------------------------+ | find_in_set("33","1,3,33,4,55,44") | +------------------------------------+ | 3 | +------------------------------------+ 1 row in set (0.00 sec) mysql> select find_in_set("55","1,3,33,4,55,44"); +------------------------------------+ | find_in_set("55","1,3,33,4,55,44") | +------------------------------------+ | 5 | +------------------------------------+ 1 row in set (0.00 sec) mysql> select field("song","xiao","zhan","song","yong"); +-------------------------------------------+ | field("song","xiao","zhan","song","yong") | +-------------------------------------------+ | 3 | +-------------------------------------------+ 1 row in set (0.00 sec) mysql> select field("song","xiao","zhan","yong"); +------------------------------------+ | field("song","xiao","zhan","yong") | +------------------------------------+ | 0 | +------------------------------------+ 1 row in set (0.00 sec) mysql> select position("song" in "xiaosong") 位置, -> locate("song","xiaosong") 位置, -> instr("song","xiaosong") 位置; +------+------+------+ | 位置 | 位置 | 位置 | +------+------+------+ | 5 | 5 | 0 | +------+------+------+ 1 row in set (0.00 sec) mysql> select position("song" in "xiaosong") 位置, -> locate("song","xiaosong") 位置, -> instr("xiaosong","song") 位置; +------+------+------+ | 位置 | 位置 | 位置 | +------+------+------+ | 5 | 5 | 5 | +------+------+------+ 1 row in set (0.00 sec) mysql> select replace("这是我的mysql服务器","mysql","php"); +----------------------------------------------+ | replace("这是我的mysql服务器","mysql","php") | +----------------------------------------------+ | 这是我的php服务器 | +----------------------------------------------+ 1 row in set (0.00 sec) mysql> select abs(10); +---------+ | abs(10) | +---------+ | 10 | +---------+ 1 row in set (0.00 sec) mysql> select abs(-10); +----------+ | abs(-10) | +----------+ | 10 | +----------+ 1 row in set (0.00 sec) mysql> select cell(3.3); ERROR 1305 (42000): FUNCTION test.cell does not exist mysql> select ceil(3.3); +-----------+ | ceil(3.3) | +-----------+ | 4 | +-----------+ 1 row in set (0.00 sec) mysql> select floor(3.3); +------------+ | floor(3.3) | +------------+ | 3 | +------------+ 1 row in set (0.00 sec) mysql> select mod(2,3); +----------+ | mod(2,3) | +----------+ | 2 | +----------+ 1 row in set (0.00 sec) mysql> select mod(9,3); +----------+ | mod(9,3) | +----------+ | 0 | +----------+ 1 row in set (0.00 sec) mysql> select mod(7,3); +----------+ | mod(7,3) | +----------+ | 1 | +----------+ 1 row in set (0.00 sec) mysql> select rand() -> ; +--------------------+ | rand() | +--------------------+ | 0.2543807385995805 | +--------------------+ 1 row in set (0.00 sec) mysql> select ceil(rand()*10000); +--------------------+ | ceil(rand()*10000) | +--------------------+ | 6921 | +--------------------+ 1 row in set (0.00 sec) mysql> select ceil(rand()*10000); +--------------------+ | ceil(rand()*10000) | +--------------------+ | 6974 | +--------------------+ 1 row in set (0.00 sec) mysql> select ceil(rand()*10000); +--------------------+ | ceil(rand()*10000) | +--------------------+ | 4104 | +--------------------+ 1 row in set (0.00 sec) mysql> select ceil(rand()*10000); +--------------------+ | ceil(rand()*10000) | +--------------------+ | 9597 | +--------------------+ 1 row in set (0.00 sec) mysql> select ceil(rand()*10000); +--------------------+ | ceil(rand()*10000) | +--------------------+ | 5675 | +--------------------+ 1 row in set (0.00 sec) mysql> select ceil(rand()*10000); +--------------------+ | ceil(rand()*10000) | +--------------------+ | 9580 | +--------------------+ 1 row in set (0.00 sec) mysql> select ceil(rand()*10000); +--------------------+ | ceil(rand()*10000) | +--------------------+ | 877 | +--------------------+ 1 row in set (0.00 sec) mysql> select ceil(rand()*10000); +--------------------+ | ceil(rand()*10000) | +--------------------+ | 5645 | +--------------------+ 1 row in set (0.00 sec) mysql> select ceil(rand()*10000); +--------------------+ | ceil(rand()*10000) | +--------------------+ | 5592 | +--------------------+ 1 row in set (0.00 sec) mysql> select ceil(rand()*10000); +--------------------+ | ceil(rand()*10000) | +--------------------+ | 1025 | +--------------------+ 1 row in set (0.00 sec) mysql> select ceil(rand()*1000); +-------------------+ | ceil(rand()*1000) | +-------------------+ | 835 | +-------------------+ 1 row in set (0.00 sec) mysql> select ceil(rand()*1000); +-------------------+ | ceil(rand()*1000) | +-------------------+ | 868 | +-------------------+ 1 row in set (0.00 sec) mysql> select ceil(rand()*1000); +-------------------+ | ceil(rand()*1000) | +-------------------+ | 833 | +-------------------+ 1 row in set (0.00 sec) mysql> select ceil(rand()*1000); +-------------------+ | ceil(rand()*1000) | +-------------------+ | 560 | +-------------------+ 1 row in set (0.00 sec) mysql> select ceil(rand()*10000); +--------------------+ | ceil(rand()*10000) | +--------------------+ | 2991 | +--------------------+ 1 row in set (0.00 sec) mysql> mysql> select ceil(rand()*10000); +--------------------+ | ceil(rand()*10000) | +--------------------+ | 8176 | +--------------------+ 1 row in set (0.00 sec) mysql> select ceil(rand()*10000); +--------------------+ | ceil(rand()*10000) | +--------------------+ | 1907 | +--------------------+ 1 row in set (0.00 sec) mysql> select ceil(rand()*10000); +--------------------+ | ceil(rand()*10000) | +--------------------+ | 5005 | +--------------------+ 1 row in set (0.00 sec) mysql> select ceil(rand()*10000); +--------------------+ | ceil(rand()*10000) | +--------------------+ | 9306 | +--------------------+ 1 row in set (0.00 sec) mysql> select ceil(rand()*10000); +--------------------+ | ceil(rand()*10000) | +--------------------+ | 1513 | +--------------------+ 1 row in set (0.00 sec) mysql> select ceil(rand()*10000); +--------------------+ | ceil(rand()*10000) | +--------------------+ | 9648 | +--------------------+ 1 row in set (0.00 sec) mysql> select ceil(rand()*10000); +--------------------+ | ceil(rand()*10000) | +--------------------+ | 3698 | +--------------------+ 1 row in set (0.00 sec) mysql> select ceil(rand()*10000); +--------------------+ | ceil(rand()*10000) | +--------------------+ | 9547 | +--------------------+ 1 row in set (0.00 sec) mysql> select ceil(rand()*10000); +--------------------+ | ceil(rand()*10000) | +--------------------+ | 6640 | +--------------------+ 1 row in set (0.00 sec) mysql> select truncate(22.333,2); +--------------------+ | truncate(22.333,2) | +--------------------+ | 22.33 | +--------------------+ 1 row in set (0.00 sec) mysql> select truncate(22.339,2); +--------------------+ | truncate(22.339,2) | +--------------------+ | 22.33 | +--------------------+ 1 row in set (0.00 sec) mysql> select round(4.5); +------------+ | round(4.5) | +------------+ | 5 | +------------+ 1 row in set (0.00 sec) mysql> select round(4.3); +------------+ | round(4.3) | +------------+ | 4 | +------------+ 1 row in set (0.00 sec) mysql> select round(4.33333); +----------------+ | round(4.33333) | +----------------+ | 4 | +----------------+ 1 row in set (0.00 sec) mysql> select round(4.33333,1); +------------------+ | round(4.33333,1) | +------------------+ | 4.3 | +------------------+ 1 row in set (0.00 sec) mysql> select round(4.33333,3); +------------------+ | round(4.33333,3) | +------------------+ | 4.333 | +------------------+ 1 row in set (0.00 sec) mysql> select round(4.33333,2); +------------------+ | round(4.33333,2) | +------------------+ | 4.33 | +------------------+ 1 row in set (0.00 sec) mysql> select round(4.33933,2); +------------------+ | round(4.33933,2) | +------------------+ | 4.34 | +------------------+ 1 row in set (0.00 sec) mysql> select curdate(); +------------+ | curdate() | +------------+ | 2017-12-19 | +------------+ 1 row in set (0.00 sec) mysql> select curtime(); +-----------+ | curtime() | +-----------+ | 21:38:13 | +-----------+ 1 row in set (0.00 sec) mysql> select now -> -> \c mysql> select now(); +---------------------+ | now() | +---------------------+ | 2017-12-19 21:39:15 | +---------------------+ 1 row in set (0.00 sec) mysql> select date(now()); +-------------+ | date(now()) | +-------------+ | 2017-12-19 | +-------------+ 1 row in set (0.00 sec) mysql> select time(now()); +-------------+ | time(now()) | +-------------+ | 21:39:29 | +-------------+ 1 row in set (0.00 sec) mysql> select time("2017-12-19 17:33:22"); +-----------------------------+ | time("2017-12-19 17:33:22") | +-----------------------------+ | 17:33:22 | +-----------------------------+ 1 row in set (0.00 sec) mysql> select time("2017-12-19 17:33:22"); +-----------------------------+ | time("2017-12-19 17:33:22") | +-----------------------------+ | 17:33:22 | +-----------------------------+ 1 row in set (0.00 sec) mysql> select week(now()); +-------------+ | week(now()) | +-------------+ | 51 | +-------------+ 1 row in set (0.00 sec) mysql> select week("2017-12-16"); +--------------------+ | week("2017-12-16") | +--------------------+ | 50 | +--------------------+ 1 row in set (0.00 sec) mysql> select year("2017-12-16"); +--------------------+ | year("2017-12-16") | +--------------------+ | 2017 | +--------------------+ 1 row in set (0.00 sec) mysql> select unix_timestamp(now()); +-----------------------+ | unix_timestamp(now()) | +-----------------------+ | 1513690980 | +-----------------------+ 1 row in set (0.00 sec) mysql> select from_unixtime(1513690980); +---------------------------+ | from_unixtime(1513690980) | +---------------------------+ | 2017-12-19 21:43:00 | +---------------------------+ 1 row in set (0.00 sec) mysql> select from_unixtime(1513690989); +---------------------------+ | from_unixtime(1513690989) | +---------------------------+ | 2017-12-19 21:43:09 | +---------------------------+ 1 row in set (0.00 sec) mysql> select now() 当前时间, -> select year(now()) 年份, -> select quarter(now()) 季度, -> select month(now()) 月, -> \c mysql> select now() 当前时间, -> year(now()) 年份, -> quarter(now()) 季度, -> month(now()) 月, -> week(now()) 星期周期, -> dayofmonth(now()) 天, -> hour(now()) 时, -> minute(now()) 分, -> second(now()) 秒; +---------------------+------+------+------+----------+------+------+------+------+ | 当前时间 | 年份 | 季度 | 月 | 星期周期 | 天 | 时 | 分 | 秒 | +---------------------+------+------+------+----------+------+------+------+------+ | 2017-12-19 21:49:51 | 2017 | 4 | 12 | 51 | 19 | 21 | 49 | 51 | +---------------------+------+------+------+----------+------+------+------+------+ 1 row in set (0.00 sec) mysql> select day(now()); +------------+ | day(now()) | +------------+ | 19 | +------------+ 1 row in set (0.00 sec) mysql> select now() 当前时间, -> week(now()) 年中的第几个星期, -> dayname(now()) 星期, -> dayofweek(now()) xingqi, -> weekday(now()) 星期; +---------------------+------------------+---------+--------+------+ | 当前时间 | 年中的第几个星期 | 星期 | xingqi | 星期 | +---------------------+------------------+---------+--------+------+ | 2017-12-19 21:52:48 | 51 | Tuesday | 3 | 1 | +---------------------+------------------+---------+--------+------+ 1 row in set (0.00 sec) mysql> select dayofyear(now()); +------------------+ | dayofyear(now()) | +------------------+ | 353 | +------------------+ 1 row in set (0.00 sec) mysql> select dayofmonth(now()); +-------------------+ | dayofmonth(now()) | +-------------------+ | 19 | +-------------------+ 1 row in set (0.00 sec) mysql> mysql> mysql> mysql> select to_days("2017-06-18 12:22:55"); +--------------------------------+ | to_days("2017-06-18 12:22:55") | +--------------------------------+ | 736863 | +--------------------------------+ 1 row in set (0.00 sec) mysql> select to_days("2017-06-11 18:11:35"); +--------------------------------+ | to_days("2017-06-11 18:11:35") | +--------------------------------+ | 736856 | +--------------------------------+ 1 row in set (0.00 sec) mysql> select to_days("2017-06-18 12:22:55")-to_days("2017-06-11 18:11:35"); +---------------------------------------------------------------+ | to_days("2017-06-18 12:22:55")-to_days("2017-06-11 18:11:35") | +---------------------------------------------------------------+ | 7 | +---------------------------------------------------------------+ 1 row in set (0.00 sec) mysql> select datediff("2016-12-31","2017-01-05"); +-------------------------------------+ | datediff("2016-12-31","2017-01-05") | +-------------------------------------+ | -5 | +-------------------------------------+ 1 row in set (0.00 sec) mysql> select datediff("2017-12-31","2017-01-05"); +-------------------------------------+ | datediff("2017-12-31","2017-01-05") | +-------------------------------------+ | 360 | +-------------------------------------+ 1 row in set (0.00 sec)