Solved Count Number of times a customer appears (1 Viewer)

Number11

Member
Local time
Today, 01:28
Joined
Jan 29, 2020
Messages
607
I need a query to count the number of times a customer account number appears in a table and update a count total with the results, but to only count the records that have the OrderStatus as "Completed"


SELECT [CustomerAC], Sum(IIf([OrderStatusDevice] = "Completed", 1, 0)) As CountTotal
FROM Orders_Master


This is not working and i am getting...

Your query does not include the specified expression "CustomerAC" as part of an aggregate funtion.
 

Ranman256

Well-known member
Local time
Yesterday, 20:28
Joined
Apr 9, 2015
Messages
4,337
select [customer], Count([customer]) from table where [OrderStatus]='Completed'
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:28
Joined
May 7, 2009
Messages
19,231
you can also use Total query?

select [CustomerAC], Sum([OrderStatusDevice]) As CountTotal
FROM Order_Master
Where [OrderStatusDevice] = "Completed"
Group By [CustomerAC]
 

plog

Banishment Pending
Local time
Yesterday, 19:28
Joined
May 11, 2011
Messages
11,645
Neither of those queries worked did they? Ranman did the exact same thing you did and arnel tried to SUM text.

Back to your query:

SELECT [CustomerAC], Sum(IIf([OrderStatusDevice] = "Completed", 1, 0)) As CountTotal
FROM Orders_Master

Whenever you use an aggregate function (SUM, COUNT, MAX, etc.) in the SELECT, every other field in the SELECT that does not have an aggregate function must appear in the GROUP BY clause. You have no GROUP BY. So, you need to add one and put [CustomerAC] in it.
 

Users who are viewing this thread

Top Bottom