我正在尝试在将日期时间转换为用户时区后选择MIN
日期convert_tz
COUNT
也是如此:
MIN(CONVERT_TZ(dateTime,'+00:00', '+03:00')) AS dateTime,
COUNT(CONVERT_TZ(dateTime,'+00:00', '+03:00')) AS daygroup,
而且它似乎没有按预期工作。
CREATE TABLE sql_test_a
(
ID VARCHAR(255),
dateTime TIMESTAMP
);
INSERT INTO sql_test_a (ID, dateTime) VALUES ('1', '2019-04-08 19:51:00');
INSERT INTO sql_test_a (ID, dateTime) VALUES ('2', '2019-04-08 19:52:00');
INSERT INTO sql_test_a (ID, dateTime) VALUES ('3', '2019-04-10 19:53:00');
SELECT
MIN(CONVERT_TZ(dateTime,'+00:00', '+03:00')) AS dateTime,
COUNT(CONVERT_TZ(dateTime,'+00:00', '+03:00')) AS daygroup,
MIN(dateTime) AS dateTime1,
COUNT(dateTime) AS daygroup1
FROM sql_test_a
ORDER BY dateTime
当我测试它时,似乎没有 http://sqlfiddle.com 转换的 MIN 输出 2019-04-08 22:51:00 而不是转换的 MIN 输出 2019-04-08T19:51:00Z 是否可以从转换后的 MIN 输出带有 T 和 Z 的时间戳?
要考虑的事情...
这是一个只有 131072 行的数据集...
SELECT MIN(CONVERT_TZ(dateTime,'+00:00', '+03:00')) AS dateTime FROM my_table;
+---------------------+
| dateTime |
+---------------------+
| 2001-01-01 03:00:00 |
+---------------------+
1 row in set (0.56 sec)
SELECT CONVERT_TZ(MIN(dateTime),'+00:00', '+03:00') AS dateTime FROM my_table;
+---------------------+
| dateTime |
+---------------------+
| 2001-01-01 03:00:00 |
+---------------------+
1 row in set (0.04 sec)