选择两个日期之间的记录 [英] Selecting records between two dates

查看:114
本文介绍了选择两个日期之间的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下查询:

SELECT dm.app_id, apt.app_name, COUNT(dm.app_id) 
FROM dm_openapp dm
JOIN app_table apt ON dm.app_id = apt.app_id
GROUP BY dm.app_id 

基本上这个表还有与每条记录相关联的日期,我需要在X和Y之间得到所有记录的范围,我尝试使用以下例子,但是没有用:

Basically this table also has dates associated to each record, and I need to get a range of all the records between time X and Y, I tried using the following, for example, but to no avail:

WHERE dm.dl_time BETWEEN '2011-05-31' AND '2011-05-06'

有什么想法要做什么? dl_time列是一个时间戳类型。

Any idea as to what to do? the dl_time column is a timestamp type.

推荐答案

嗯...你有数据错误的方式。 BETWEEN 必须为LOW值到HIGH值:

Ummm... you've got the data the wrong way around. BETWEEN must be LOW value to HIGH value:

尝试这样:

WHERE dm.dl_time BETWEEN '2011-05-06' AND '2011-05-31' -- Note date values swapped

您可以忽略其他答案,也没有注意到这一点...

You can ignore the other answers, which also haven't noticed this...

这篇关于选择两个日期之间的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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