在EXTRACT()查询中出现语法错误,缺少哪个操作符?

huangapple go评论98阅读模式
英文:

Syntax error in EXTRACT() query, what operator is missing?

问题

我有一个在MS Access中的表格,用于跟踪我们游泳池会员使用游泳通行证签到的情况,看起来像这样:

在EXTRACT()查询中出现语法错误,缺少哪个操作符?

我尝试生成一个报告,以显示数据,以便我可以看到每个运营年度我们有多少“签到”次数,如下所示:

季节    访问次数
2021     432
2020     123
2019     354
等等。

我的计划是从CHECKINTIME中提取年份,然后计算该年份中唯一ID的数量。
我正在使用以下SQL进行查询:

选择 
  EXTRACT(YEAR FROM tblCheckIn.[CHECKINTIME]) AS Season,
  COUNT(tblCheckIn.[ID]) AS Visits
FROM tblCheckIn
GROUP BY (YEAR FROM tblCheckIn.[CHECKINTIME]);

现在我得到以下错误:查询表达式中的语法错误(缺少运算符)'EXTRACT(YEAR FROM tblCheckIn.[CHECKINTIME])' 我一直在查看EXTRACT()的文档,但我无法弄清楚我做错了什么。我猜想这可能是特定于MS Access的问题?

英文:

I have a table in MS Access that tracks when members of our pool check in with their pool pass that looks like this:

在EXTRACT()查询中出现语法错误,缺少哪个操作符?

I'm trying to generate a report that displays the data so I can see how many 'Check-Ins' we've had for each year of operation like so:

Season   Visits
2021     432
2020     123
2019     354
etc.

My plan is to extract the year from the CHECKINTIME, then count the number of unique ID's in that year.
I'm using the following SQL for my query:

SELECT 
  EXTRACT(YEAR FROM tblCheckIn.[CHECKINTIME]) AS Season,
  COUNT(tblCheckIn.[ID]) AS Visits
FROM tblCheckIn
GROUP BY (YEAR FROM tblCheckIn.[CHECKINTIME]);

Right now I'm getting the following error: Syntax error (missing operator) in query expression 'EXTRACT(YEAR FROM tblCheckIn.[CHECKINTIME]) I've been pouring over the documentation for EXTRACT() but I can't figure out what I'm doing wrong. I'm guessing it's specifically an MS Access thing?

答案1

得分: 2

Ms Access使用YEAR函数而不是extract

SELECT 
  YEAR(tblCheckIn.[CHECKINTIME]) AS Season,
  COUNT(tblCheckIn.[ID]) AS Visits
FROM tblCheckIn
GROUP BY YEAR(tblCheckIn.[CHECKINTIME]);

或者您可以使用:

SELECT DatePart("yyyy",tblCheckIn.[CHECKINTIME]) AS NewDate FROM tblCheckIn;
英文:

Ms Access uses a YEAR function and not extract

SELECT 
  YEAR(tblCheckIn.[CHECKINTIME]) AS Season,
  COUNT(tblCheckIn.[ID]) AS Visits
FROM tblCheckIn
GROUP BY YEAR(tblCheckIn.[CHECKINTIME]);

or you can use

SELECT DatePart("yyyy",tblCheckIn.[CHECKINTIME]) AS NewDate FROM tblCheckIn; 

huangapple
  • 本文由 发表于 2023年2月7日 00:37:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75364115.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定