5

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

'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) ""
}
4

3 回答 3

7

我猜那posted是一个DATETIME. 您可以使用0.

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

是相同的

posted = 0
于 2012-06-18T15:55:32.327 回答
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)
于 2012-06-18T15:48:56.247 回答
0
SELECT max(id) as id FROM orders WHERE posted=0;
于 2012-06-18T15:49:02.237 回答