473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Cannot have Aggregate Function in Where Clause Error

anoble1
245 128KB
I need some help.
I am getting this error when I changed the SQL statement and added the function "LAST"

Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT Last(tblEntrys.OdometerReading) AS LastOfOdometerReading, Last(tblEntrys.DateEntered) AS LastOfDateEntered FROM tblEntrys WHERE (((tblEntrys.Vehicle) = " & Vehicle & ") And Last(((tblEntrys.DateEntered)) < #" & Now() & "#)) ORDER BY Last(tblEntrys.DateEntered) DESC;"
I am missing something. But, I cannot find it. I am looking for the last date one of our vehicles data was entered so I can grab the last date to get that mileage that was put in.
May 16 '18 #1

✓ answered by Rabbit

LAST is an aggregate function. You can't have aggregate functions in the WHERE clause. To filter on an aggregate function, you have to use the HAVING clause.

2 1816
Rabbit
12,516 Expert Mod 8TB
LAST is an aggregate function. You can't have aggregate functions in the WHERE clause. To filter on an aggregate function, you have to use the HAVING clause.
May 16 '18 #2
anoble1
245 128KB
Awesome. That worked like a champ!
May 16 '18 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Bill Moran | last post by:
Hey all. I've hit an SQL problem that I'm a bit mystified by. I have two different questions regarding this problem: why? and how do I work around it? The following query: SELECT GCP.id,...
2
by: Zygo Blaxell | last post by:
I have a table with a few million rows of temperature data keyed by timestamp. I want to group these rows by timestamp intervals (e.g. every 32 seconds), compute aggregate functions on the...
2
by: rdemyan via AccessMonster.com | last post by:
I can't seem to get the following SQL statement with the ORDER BY clause to work. It does work if I order by any of the fields in the SELECT part of the statement but not if it is the field in the...
5
by: BillCo | last post by:
I just wasted a long time figuring out this and I figure if I post it might save someone some pain! Jet (DAO) will allow you to to use nested aggregate functions like building blocks, e.g.: ...
2
by: Jim.Mueksch | last post by:
I am having a problem with using calculated values in a WHERE clause. My query is below. DB2 gives me this error message: Error: SQL0206N "APPRAISAL_LESS_PRICE" is not valid in the context where...
5
by: pwiegers | last post by:
Hi, I'm trying to use the result of a conditional statement in a where clause, but i'm getting 1)nowhere 2) desperate :-) The query is simple: -------- SELECT idUser,...
7
by: kpfunf | last post by:
Getting the following error opening a report, cannot figure out the cause: "You tried to execute a query that does not include the specified expression 'RQ_FuelQuoteReportHistory.Vendor' as part...
6
by: Kelii | last post by:
Hello, So I have a form which shows all items available for sale, when it was last sold, where it was last sold, and whether it is active or inactive. I would like to be able to edit the...
10
by: Qtip23 | last post by:
Hello All, I am unable to get my VBA code to show all the records and allow me to view the filtered responses from user input, once my cmd_click() event fires. The form displays the 19...
1
by: Jagdeep singh | last post by:
There are 2 tables 1.customers 2.quotations Here I fill my datagridview with this query SELECT quotations.CustomerKey as Id , customers.Name , SUM(quotations.AmountDue)...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.