Max F
Max F

Reputation: 81

Sql query not part of aggregate function

when I run the following query in access

SELECT SUM(RegBed) AS RegBedTOTAL, PostcodeRESULTS_PostcodeNS as postcode
FROM cooltableless10;

I get the following error:

this query does not include the specified expression 'postcode' as part of an aggregate function.

Could somebody tell me why it is so?

Upvotes: 0

Views: 9164

Answers (2)

jaoski
jaoski

Reputation: 1

you need to add a group by clause and group it by postcode add some like this on your query:

group by postcode

you always need to add group by clause and group your data when using aggregate functions on your query

Upvotes: 0

Gerf
Gerf

Reputation: 311

SUM is an aggregate function, which means that any non-aggregated columns must be included in a GROUP BY clause. Try this:

SELECT SUM(RegBed) AS RegBedTOTAL, PostcodeRESULTS_PostcodeNS as postcode
FROM cooltableless10
GROUP BY PostcodeRESULTS_PostcodeNS

Upvotes: 3

Related Questions