日期时间值不正确:'2014-10-19 00:00:00'列时间为 第2300行
如何修复SQL替换查询以避免错误的日期时间值:'2014-10-19 00:00:00'表示第2300行的列时间。
在巴西,DST发生在2014年10月19日星期日,12:00:午夜时钟转发1小时到2014年10月19日星期日,当地白天时间凌晨1:00:00而MYSQL服务器只是不喜欢2014-10-19 00:00:00因为它不是真正有效的时间,应该是2014-10-19 01:00:00
安装在具有Timezone(UTC-03:00)Barasilia的操作系统上的Mysql服务器
CREATE TABLE `Table1` (
`Group` bigint(20) unsigned NOT NULL,
`Type` enum('Electric_Energy','Electric_Apparent','Gas_Volume','Gas_Energy','Water_Volume','Water_Energy','Thermal_Energy','Steam_Weight','Temperature','Carbon_Emission','Fuel_Volume') COLLATE utf8_bin NOT NULL,
`Aggregation` enum('Sum','Avg','Max','Min') COLLATE utf8_bin NOT NULL,
`Period` char(1) COLLATE utf8_bin NOT NULL,
`Timestamp` timestamp NOT NULL,
`Value` decimal(38,10) NOT NULL,
PRIMARY KEY (`Group`,`Timestamp`,`Type`,`Aggregation`,`Period`),
KEY `IDX_Table1_group_period_timestamp` (`Group`,`Period`,`Timestamp`),
CONSTRAINT `FK_Table1_Group` FOREIGN KEY (`Group`) REFERENCES `group1` (`ID`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin ROW_FORMAT=COMPRESSED;
CREATE TABLE `Table2` (
`ID` bigint(20) unsigned NOT NULL,
`Value` decimal(38,10) NOT NULL,
`Timestamp` timestamp NOT NULL,
PRIMARY KEY (`ID`,`Timestamp`),
CONSTRAINT `FK_Table2_ID` FOREIGN KEY (`ID`) REFERENCES `Table3` (`ID`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
REPLACE INTO `Table1` SELECT 898 `Group`, "Water_Volume" `Type`, "Sum" `Aggregation`, "D" `Period`, CONCAT(DATE_FORMAT(`t1`.`Timestamp`, "%Y-%m-%d"), " 00:00:00") `Timestamp`,Sum(`t1`.`Value`) `Value` FROM (SELECT SUM(`Value`) `Value`, `Timestamp` FROM `Table2` WHERE `ID` IN (1438, 1439) AND `Timestamp` BETWEEN "2014-10-12 00:00:00" AND "2014-10-19 23:59:59" GROUP BY `Timestamp`) `t1` GROUP BY DATE_FORMAT(`t1`.`Timestamp`, "%Y-%m-%d");
答案 0 :(得分:0)
我不知道补偿夏令时漏洞的官方方法,但这样的事情应该是简单的,一次性使用,处理它的方式。
CONCAT(DATE_FORMAT(`t1`.`Timestamp`, "%Y-%m-%d")
, IF(DATE_FORMAT(`t1`.`Timestamp`, "%Y-%m-%d")="2014-10-19", " 01:00:00", " 00:00:00")
)
如果不像往常一样在美国跳跃,你可能会想出一个更持久的测试,如
MONTH(`t1`.`Timestamp`) = 10 AND DAYOFMONTH(`t1`.`Timestamp`) = 19
...或者只是统一使用01:00:00,因为您无论如何都需要在这些日期进行帐号/调整。