mysql等效表达到'0000-00-00 00:00:00'

时间:2012-06-18 15:46:05

标签: mysql

我想知道是否存在比这更短的表达式:

'0000-00-00 00:00:00'


SELECT id FROM orders WHERE posted='0000-00-00 00:00:00' ORDER BY id DESC LIMIT 1;

我的意思是:

SELECT id FROM orders WHERE posted=null ORDER BY id DESC LIMIT 1;

我希望这是您想要看到的架构:

array(19) {
  ["TABLE_CATALOG"]=>
  NULL
  ["TABLE_SCHEMA"]=>
  string(13) "teleprintfejl"
  ["TABLE_NAME"]=>
  string(13) "megrendelesek"
  ["COLUMN_NAME"]=>
  string(7) "posted"
  ["ORDINAL_POSITION"]=>
  string(2) "20"
  ["COLUMN_DEFAULT"]=>
  NULL
  ["IS_NULLABLE"]=>
  string(2) "NO"
  ["DATA_TYPE"]=>
  string(8) "datetime"
  ["CHARACTER_MAXIMUM_LENGTH"]=>
  NULL
  ["CHARACTER_OCTET_LENGTH"]=>
  NULL
  ["NUMERIC_PRECISION"]=>
  NULL
  ["NUMERIC_SCALE"]=>
  NULL
  ["CHARACTER_SET_NAME"]=>
  NULL
  ["COLLATION_NAME"]=>
  NULL
  ["COLUMN_TYPE"]=>
  string(8) "datetime"
  ["COLUMN_KEY"]=>
  string(0) ""
  ["EXTRA"]=>
  string(0) ""
  ["PRIVILEGES"]=>
  string(31) "select,insert,update,references"
  ["COLUMN_COMMENT"]=>
  string(0) ""
}

3 个答案:

答案 0 :(得分:7)

我猜postedDATETIME。您可以使用0

posted = '0000-00-00 00:00:00'

相同
posted = 0

答案 1 :(得分:0)

这取决于您的结构,当您创建它时,您可以使用null作为默认值,当您进行选择时,您将使用:

SELECT id FROM orders WHERE posted IS null ORDER BY id DESC LIMIT 1;

修改

mysql> create table tiempo (fecha datetime);
Query OK, 0 rows affected (0.04 sec)

mysql> insert into tiempo values ();
Query OK, 1 row affected (0.00 sec)

mysql> select * from tiempo;
+-------+
| fecha |
+-------+
| NULL  |
+-------+
1 row in set (0.00 sec)

mysql> insert into tiempo values ('2000-02-02 02:02:02');
Query OK, 1 row affected (0.00 sec)

mysql> select * from tiempo;
+---------------------+
| fecha               |
+---------------------+
| NULL                |
| 2000-02-02 02:02:02 |
+---------------------+
2 rows in set (0.00 sec)

mysql> select * from tiempo where fecha is not null;
+---------------------+
| fecha               |
+---------------------+
| 2000-02-02 02:02:02 |
+---------------------+
1 row in set (0.00 sec)

答案 2 :(得分:0)

SELECT max(id) as id FROM orders WHERE posted=0;