SELECT FLOOR(7 + (RAND() * 6)); 取7到12的随机整数,包括7到12
SELECT FLOOR(12+(rand()*13)); 取12到24的随机整数,包括12到24
LPAD(FLOOR(0 + (RAND() * 23)),2,0) 取0-24之间的随机数,不够2位的前补0
格式 : 2018-12-11 17:43:11
举例:
给用户赋一个随机入职日期,年份为1990-2014
select CONCAT(FLOOR(1990 + (RAND() * 25)),'-',LPAD(FLOOR(1 + (RAND() * 12)),2,0),'-',LPAD(FLOOR(3 + (RAND() * 8)),2,0))
结果:
select CONCAT(LPAD(FLOOR(0 + (RAND() * 23)),2,0),':',LPAD(FLOOR(0 + (RAND() * 59)),2,0),':',LPAD(FLOOR(0 + (RAND() * 59)),2,0))
结果: