我想检索当月 1 -30 之间的数据 [我正在使用 MSACCESS Dbase 来执行此操作] 下面是我正在尝试的查询 --
SELECT count(usercategory) as category_count ,usercategory FROM user_category
where IssueDate between DATEADD('m', DATEDIFF('m', 0, DATE()) - 0 , 0) and DATEADD('m', DATEDIFF('m', 0, DATE()) + 1, - 1 ) group by usercategory
我在 MSACCESS 数据库中保存的数据 -
Category1 9/7/2013 12:00:00 AM
Category1 9/8/2013 12:00:00 AM
Category2 10/8/2013 12:00:00 AM
所以输出应该只有 2 条记录
但我的查询没有给出结果
这是我认为您需要的查询。它使用的所有函数始终在 Access SQL 中可用,无论查询是在 Access 会话内还是在 Access 会话外运行(如在 c# 情况下)。
数据库引擎将评估这两个DateSerial
表达式一次,然后使用其结果来过滤结果集。如果有索引,这种方法会特别快IssueDate
.
SELECT
Count(usercategory) AS category_count,
usercategory
FROM user_category
WHERE
IssueDate >= DateSerial(Year(Date()), Month(Date()), 1)
AND IssueDate < DateSerial(Year(Date()), Month(Date()) + 1, 0)
GROUP BY usercategory;
这是一个 Access Immediate 窗口会话,它解释了这些的逻辑DateSerial
表达...
? Date()
9/6/2013
? Year(Date())
2013
? Month(Date())
9
' get the date for first of this month ...
? DateSerial(Year(Date()), Month(Date()), 1)
9/1/2013
' now get the date for the last of this month ...
? DateSerial(Year(Date()), Month(Date()) + 1, 0)
9/30/2013
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)