mercredi 6 novembre 2019

Populating A Table with Random Dates or Null Vallues

I would like to populate a column in my table with either random dates from the past or Null Values. I would like to set the random dates between two dates, January 1 1920 and December 1 2018, or NULL VALUES.

I've come accross some confusing code that could be a solution for generating a random date during a specific period, but it doesn't cater for the null values.

INSERT INTO `FootballPlayers` VALUES (SELECT timestamp('2010-04-30') - INTERVAL FLOOR( RAND( ) * 366) DAY);

I would like for the column of the table to have something like.

+----------------+
|  Date of Death |
+----------------+
|   20/10/1990   |
|   01/11/1988   |
|   04/02/2006   |
|      NULL      |
|   17/05/2011   |
|   22/04/1972   |
|      NULL      |
|      NULL      |
|   13/04/1989   |
|   10/03/1999   |
+----------------+



Aucun commentaire:

Enregistrer un commentaire