Home > Mobile >  How to include COUNT function in where clause?
How to include COUNT function in where clause?

Time:01-18

I've got a customer records table. I'm trying to get the data for only customers that have visited 10 times since a specific date. Here's the code I've got right now. Any help troubleshooting would be greatly appreciated!

    Select 
         customer_id,
         order_id,
         order_date
    from Table1
    where order_date > '2020-02-01'
    group by customer_id
    having count(customer_id)>=10

CodePudding user response:

You should not mix grouped and "normal" columns in a select

select *
from table1
where customer_id in
(
    Select customer_id
    from Table1
    where order_date > '2020-02-01'
    group by customer_id
    having count(*) >= 10
)
  •  Tags:  
  • Related