您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

mysql 日期比较有关问题

2024/3/10 10:12:14发布20次查看
mysql 日期比较问题
现在表kucun中有datavalue(varchar,是2012-01-01这样的格式日期)和price(float 11,2)字段
现在我想获取2012-07-10到2012-08-10中的数据我的写法是这样的
1,
select * from `kucun` where datavalue between 'unix_timestamp(2012-07-10)' and 'unix_timestamp(2012-08-10)'
结果为空
2,
select * from `kucun` where datavalue between '2012-07-10' and '2012-08-10'
结果正确,获取我想要找的数据了
3,
select * from `kucun` where unix_timestamp(datavalue)>unix_timestamp(2012-07-10) and unix_timestamp(datavalue)结果为空
为么1和3在为空呢?2这样写正规吗?xxxx-xx-xx 这样的格式日期可以比较吗?
------解决方案--------------------
1、
select * from `kucun` where datavalue between 'unix_timestamp(2012-07-10)' and 'unix_timestamp(2012-08-10)'
要删去多余的引号
3、
select * from `kucun` where unix_timestamp(datavalue)>unix_timestamp('2012-07-10') and unix_timestamp(datavalue)要补上必须的引号
------解决方案--------------------
unix_timestamp()函数的字符串参数要加引号,这样试试:
sql codeselect * from `kucun` where unix_timestamp(datavalue)>unix_timestamp('2012-07-10') and unix_timestamp(datavalue)
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product