您现在的位置:首页 > 博客 > SQL > 正文
access 数据库写按日期查询SQL
http://www.bbnsc.com/      2023/2/20 13:27:48      来源:csdn      点击:

具体某一年查询数据

select sum(amount) from 表名 where format(createtime,"yyyy")=2020

具体某一年某个月查询

select sum(amount) from 表名 where format(createtime,"yyyymm")=202001

按月统计某一年的数据

select sum(amount) as total,Month(createtime) as month from (select * from t_records where format(createtime,"yyyy")=2020) group by Month(createtime)

同理,按年统计一段时间内的数据

select sum(a.amount) as total,Year(a.createtime) as year from (select * from t_records where createtime between #2019-1-1 00:00:00# and #2020-12-31 23:59:59#) as a group by Year(createtime)

使用时遇到的问题

SELECT 子句中包含一个保留字、拼写错误或丢失的参数,或标点符号不正确。

把你任务是关键字的字段使用[]括起来,比如:name字段,查询时写成[name]即可。


发表评论(0)
姓名
*
评论内容
*
验证码
*图片看不清?点击重新得到验证码