Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何编写一个基于列值返回真/假(实际上是 1/0)的 MySQL 查询。
在我的实例中,我想为日期时间 col 返回“hasDate”,我们称之为 myDateTime
如果 myDateTime 的值为 000-00-00 00:00:00 我想返回 hasDate 0 (false)
如果 myDateTime 有任何其他值,我想返回 hasDate of 1 (true)
感谢你的协助。
使用IF声明
IF
SELECT IF(myDateTime = '0000-00-00 00:00:00',0,1) AS hasDate FROM myTable
但最好的办法是改变你的数据结构以避免这样做。