MySQL IN BETWEEN没有条件 [英] MySQL IN BETWEEN with no condition

查看:241
本文介绍了MySQL IN BETWEEN没有条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个SQL查询,如果datetime没有被分配我想替换一个字符串,可以选择所有的日期和时间。

I want to write a SQL query where if the datetime is not been assigned I want to replace a string which can select all date and time.

works:

    SELECT * FROM `entry` WHERE `user` like 'TOM' or `user` like 'PHP'
 and `entry_datetime` between '2013-03-13 22:20:18' and '2013-03-13 22:20:26' 

我的怀疑:
如果php没有获得日期的值,并且我不想通过删除AND条件更改查询,但我想要在日期和时间之间替换一些东西,仍然应该运行查询:

My Doubt: If the php do not get the value of the date from and to but I don't want to change the query by deleting the AND condition but I want to replace some thing in between date and time and still the query should run:

    SELECT * FROM `entry` WHERE `user` like 'TOM' or `user` like 'PHP' and 
`entry_datetime` between ' ' and ' '

我试过下面但是它不工作?我们可以这样写一个查询?

I tried the following but its not working? can we write a query like this?

    SELECT * FROM `entry` WHERE `user` like 'TOM' or `user` like 'PHP' and 
`entry_datetime` between '%%' and '%%'

我只是尝试上面这样,因为我们在LIKE命令中使用它,所以我试试?任何建议将是很有帮助。

I just tries the above like because we use it in LIKE command so I tried that? Any advice will be much helpful.

我不知道我的方式是对错,但我不能更改查询id日期值未分配。

I dont know the way I am trying is right or wrong but I can't change the Query id the date value is not assigned.

推荐答案

您可以对datetime数据类型使用MIN和MAX值。

You can use MIN and MAX values for datetime data type.

... AND `entry_datetime` BETWEEN '1000-01-01 00:00:00' AND '9999-12-31 23:59:59'




DATETIME类型用于包含日期和时间
部分的值。 MySQL以YYYY-MM-DD
HH:MM:SS格式检索并显示DATETIME值。支持的范围是1000-01-01 00:00:00到
'9999-12-31 23:59:59'。

The DATETIME type is used for values that contain both date and time parts. MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.

这篇关于MySQL IN BETWEEN没有条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆