试试这个
SELECT * FROM VQ_log
WHERE event_datetime between dateStart AND dateEnd
AND msg = :merchantID ORDER BY event desc;
顺便说一句,dateStart
值dateEnd
从哪里来merchantID
?看起来这不是您的整个查询。
编辑:
不确定您的表结构/架构是什么,但据我了解,您的event
列是varchar
类型而不是int
类型(考虑到您使用的是 MYSQL),因此您没有得到正确的顺序。
例如我试过这个:
create table mytab (page varchar(10), event varchar(10), msg varchar(20),
event_datetime datetime);
insert into mytab values('page1',772,'Hi',curdate());
insert into mytab values('page21',700,'Hello',curdate());
insert into mytab values('page3',3422,'Go',curdate());
insert into mytab values('page31',3000,'There',curdate());
然后当我运行以下查询时
SELECT * FROM mytab
WHERE event_datetime between curdate() AND '2013-07-29'
ORDER BY event;
结果是这样的(见事件栏):
PAGE EVENT MSG EVENT_DATETIME
page31 3000 There July, 28 2013 00:00:00+0000
page3 3422 Go July, 28 2013 00:00:00+0000
page21 700 Hello July, 28 2013 00:00:00+0000
page1 772 Hi July, 28 2013 00:00:00+0000
但是如果我将event
列更改int
为
create table mytab (page varchar(10), event int, msg varchar(20),
event_datetime datetime);
然后结果变成
PAGE EVENT MSG EVENT_DATETIME
page21 700 Hello July, 28 2013 00:00:00+0000
page1 772 Hi July, 28 2013 00:00:00+0000
page31 3000 There July, 28 2013 00:00:00+0000
page3 3422 Go July, 28 2013 00:00:00+0000
希望这可以帮助。