网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 服务器与数据库 > MySQL
User Name
Password
 
FAQ Members List Calendar Cheap Glasses

Reply
 
Thread Tools Display Modes
  #1   IP: 112.87.30.158
Old 2015-04-19, 08:49 AM
Garibaldi Garibaldi is offline
初级会员
 
Join Date: 2012-04-17
Posts: 1
Garibaldi 现在声名狼藉
Default Mysql取某个范围内随机日期 FLOOR和LPAD

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

格式 : 2008-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))


结果:1999-10-07

select CONCAT(LPAD(FLOOR(0 + (RAND() * 23)),2,0),':',LPAD(FLOOR(0 + (RAND() * 59)),2,0),':',LPAD(FLOOR(0 + (RAND() * 59)),2,0))


结果:15:39:18

拼好之后,再写update语句就可以了
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 03:24 AM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.