gpt4 book ai didi

mysql - MariaDB 顺序错误但在 MySQL 中正确

转载 作者:行者123 更新时间:2023-11-29 02:19:30 25 4
gpt4 key购买 nike

我的本​​地服务器上有 MySQL:5.6.17,生产服务器上有 5.5.45-MariaDB-log。给予this fiddle ,结果集在本地服务器(以及 mysql 5.5 和 5.6)上正确排序,但在 mariadb 上的生产环境中没有正确排序 - 请参见下图。知道为什么吗?这是 mariadb 错误吗?

wrong order in mariadb

最佳答案

> SELECT NULLIF('2015-11-19 15:08:22', 0);
+----------------------------------+
| NULLIF('2015-11-19 15:08:22', 0) |
+----------------------------------+
| 2015-11-19 15:08:22 |
+----------------------------------+
1 row in set, 1 warning (0.00 sec)

> SHOW WARNINGS;
+---------+------+---------------------------------------------------------+
| Level | Code | Message |
+---------+------+---------------------------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: '2015-11-19 15:08:22' |
+---------+------+---------------------------------------------------------+
1 row in set (0.00 sec)

> SELECT NULLIF('2015-11-19 15:08:22', '0000-00-00 00:00:00');
+------------------------------------------------------+
| NULLIF('2015-11-19 15:08:22', '0000-00-00 00:00:00') |
+------------------------------------------------------+
| 2015-11-19 15:08:22 |
+------------------------------------------------------+
1 row in set (0.00 sec)

尝试:

SELECT
e.id,
e.dt_competition_last_manual_check,
MAX(ec.dt_created) as m,
# GREATEST always return NULL if present among arguments
NULLIF(
GREATEST(
COALESCE(MAX(ec.dt_created), '0000-00-00 00:00:00'),
COALESCE(e.dt_competition_last_manual_check, '0000-00-00 00:00:00')
)
, '0000-00-00 00:00:00') AS most_recent_dt_created_or_checked
FROM `estates` AS `e`
LEFT JOIN `estates` AS `ec` ON e.id = ec.estates_id_duplicate
WHERE e.server = 'esk'
GROUP BY `e`.`id`
ORDER BY most_recent_dt_created_or_checked DESC;

关于mysql - MariaDB 顺序错误但在 MySQL 中正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34105330/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com