user16304089
user16304089

Reputation:

postgresql groupby count where date is between

So I have a table where I want the count of rows where the customer is McDonalds's and Date > 2019-06-30

I am trying

select "Customer",
    Count("Customer")
FROM 
   public.master_environmental_data
WHERE "Customer" = 'McDonald''s' AND "Date" > '2021-06-30';

However I am getting this error:

column "master_environmental_data.Customer" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: select "Customer",
               ^
SQL state: 42803
Character: 8

What is the correct query?

Upvotes: 0

Views: 37

Answers (1)

richyen
richyen

Reputation: 9968

Should add a GROUP BY at the end of the query:

select "Customer",
    Count("Customer")
FROM 
   public.master_environmental_data
WHERE "Customer" = 'McDonald''s' AND "Date" > '2021-06-30'
GROUP BY "Customer";

Upvotes: 1

Related Questions