我的mysql数据库里面有很多很多文章,我想用select语句查出里现在半个小时的文章。。
文章的表明叫myarticle,字段有标题 title,内容content,发表时间pubtime,其他省略。。。
比如:现在时间是2011年3月27日21:26。。我想查出从2011年3月27日21:00到2011年3月27日21:30 这个时间段的文章发表的文章。
这个查询语句怎么写呢?
select * from myarticle where pubtime between (now() - INTERVAL 30 MINUTE) and now(); 保对, 请给分. 谢谢.
[code="sql"]
select * from myarticle where pubtime between '2011-3-27 21:00' and 2011-3-27 21:30
[/code]
[quote]
比如:现在时间是2011年3月27日21:26。。我想查出从2011年3月27日21:00到2011年3月27日21:30 这个时间段的文章发表的文章
[/quote]
现在时间是26分,你查到30分干什么???
现在有一个百万条的数据库库测试:
SELECT sum(length(dest_mobile) +1 - length(replace(dest_mobile,';',''))) as channel_num
from mt_sms_200804
where date_time3 BETWEEN '2008-04-15 09:00:00' and '2008-04-15 10:00:00'
SELECT sum(length(dest_mobile) +1 - length(replace(dest_mobile,';',''))) as channel_num
from mt_sms_200804
where date_time3 like '2008-04-15 09%'
SELECT sum(length(dest_mobile) +1 - length(replace(dest_mobile,';',''))) as channel_num
from mt_sms_200804
where left(date_time3,13) = '2008-04-15 09'
每个小时的执行时间(10,11,12,13,14,15,16) :
BETWEEN AND : 2.047 sec 2.344 sec 3.562 sec 3.063 sec 2.266 sec 3.031 sec 2.562 sec
LIKE : 2.375 sec 2.531 sec 2.969 sec 3.375 sec 2.109 sec 2.250 sec 2.375 sec
LEFT() : 1.906 sec 1.938 sec 2.563 sec 3.813 sec 2.218 sec 2.750 sec 2.594 sec
(一天的数据查询时间比对)
BETWEEN AND : 5.610 sec
LIKE : 7.328
LEFT() : 5.640