Reputation: 3
I'm looking for a little assistance trying to write an SQL query because, well... I suck at it.
This is a snippet of what my table looks like:
CUSTOMERID DEVICEID STATE
GUID-1 DEVICE-1 UP
GUID-1 DEVICE-2 UP
GUID-1 DEVICE-3 UP
GUID-2 DEVICE-1 DOWN
GUID-2 DEVICE-2 DOWN
GUID-2 DEVICE-3 DOWN
GUID-3 DEVICE-1 UP
GUID-3 DEVICE-2 UP
GUID-3 DEVICE-3 DOWN
In the above example, the customer GUID-1 and GUID-2 have all of their devices UP or all of them DOWN. I want to suppress those results from showing in my query. It is customer GUID-3 that I'm trying to find. This is the customer I want to show in my query results because they have devices that are both UP and DOWN.
For what it is worth, all clients have the same number of devices, in the above example 3, but in my live database more than that.
Any query writing gurus out there?
Chuck
Upvotes: 0
Views: 53
Reputation: 1270401
If you just want the customerid, then this is a group by
query:
select customerid
from snippet t
group by customerid
having min(state) <> max(state);
Upvotes: 2