Mysql
 sql >> база данни >  >> RDS >> Mysql

MariaDB грешен ред, но правилен в MySQL

> 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;



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Да се ​​разклониш или да не се разклониш?

  2. Как мога да се свържа с MySQL на WAMP сървър?

  3. Как да изберете най-новия набор от датирани записи от таблица на mysql

  4. Какъв е максималният диапазон на varchar в MySQL?

  5. Как да задам избрания елемент в падащо меню