按具体某一年查询数据
select sum(amount) from 表名 where format(createtime,"yyyy")=
按具体某一年某个月查询
select sum(amount) from 表名 where format(createtime,"yyyymm")=01
按月统计某一年的数据
select sum(amount) as total,Month(createtime) as month from (select * from t_records where format(createtime,"yyyy")=) group by Month(createtime)
同理,按年统计一段时间内的数据
select sum(a.amount) as total,Year(a.createtime) as year from (select * from t_records where createtime between #-1-1 00:00:00# and #-12-31 23:59:59#) as a group by Year(createtime)
使用时遇到的问题
SELECT 子句中包含一个保留字、拼写错误或丢失的参数,或标点符号不正确。
把你任务是关键字的字段使用[]括起来,比如:name字段,查询时写成[name]即可。
如果觉得《access 数据库写按日期查询SQL》对你有帮助,请点赞、收藏,并留下你的观点哦!