mysql空日期,选择空的MySQL日期时间字段

Is there a better way to select empty datetime fields than this?

SELECT * FROM `table` WHERE `datetime_field` = '0000-00-00 00:00:00'

解决方案

Better in what way? That query does everything you ask of it and, provided there's an index on datetime_field, it's as fast as it's going to get.

If you're worried about the query looking "ugly", don't be. Its intent is quite clear.

The only possible improvement you could consider is to use NULLs for these zero-date/time rows, in which case your query becomes:

SELECT * FROM `table` WHERE `datetime_field` IS NULL

That's what I'd do with a standards-compliant DBMS. My understanding is that MySQL may represent true NULL datetime fields in this horrific manner, in which case I guess the IS NULL may not work.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值