SELECT SQL Syntax For Count in WHERE clause
aggregate-functions, group-by, oracle, sql
Solution
To get the customers with more than 3 devices:
select customer_id, count(device_id)
from YourTable
Group by customer_id
having count(device_id) > 3
Problem
I'm trying to construct the correct sql statement (Oracle) to get the count of device_id's for each customer_id that is greater than a given value. For example, I want to know the customer_id's that have more than 3 device_ids. A single device_id can only have one customer_id associated to it, while a customer_id may have many device_ids. ``` Table: device_id customer_id .... Data (device_id, customer_id): 00001, CUST1 00002, CUST1 00003, CUST1 00004, CUST1 00005, CUST2 00006, CUST2 ```