mysql如何在动态插入单个事务时,根据随机日期列导出月/月名,last_day(),季度数,年份

时间:2018-03-24 06:05:25

标签: mysql

mysql如何在单个事务中动态插入时,根据随机日期列导出月/月名,last_day(),季度数,年份? 例如,我有一个像'test'的表

CREATE TABLE `test` (
  `KEY` BIGINT(20) NOT NULL AUTO_INCREMENT,
  `MTH_END_DT` DATE NOT NULL,
  `DT` DATE NOT NULL,
  `FINCL_YEAR_MTH_NUM` SMALLINT(6) DEFAULT NULL,
  `FINCL_YEAR` SMALLINT(6) DEFAULT NULL,
  `FINCL_YEAR_QTR_NUM` SMALLINT(6) DEFAULT NULL,
   PRIMARY KEY (`KEY`)
) ENGINE=INNODB AUTO_INCREMENT=0 DEFAULT CHARSET=latin1;

我的插入语句就像

INSERT INTO test (`KEY`,`MTH_END_DT`,`DT`,`FINCL_YEAR_MTH_NUM`,`FINCL_YEAR`,`FINCL_YEAR_QTR_NUM`)
    VALUES (
    DEFAULT,
    [need TO derive based ON third COLUMN LIKE LAST_DAY(date1)],
    DATE(TIMESTAMPADD(SECOND, FLOOR(RAND() * TIMESTAMPDIFF(SECOND, DATE('2017-07-01'), DATE('2019-03-31'))), DATE('2017-07-01'))) AS date1, 
    [need TO derive based ON third COLUMN LIKE MONTH(date1)],
    [need TO derive based ON third COLUMN LIKE YEAR(date1)],
    [need TO derive based ON third COLUMN LIKE QUARTER(date1)]
    );

任何帮助将不胜感激!

0 个答案:

没有答案