按具体某一年查询数据
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]即可。