I tried do search other posts but could only find about finding duplicates about one fixed values.
So imagine following table:
╔══════════╦═══════╗
║ customer ║ color ║
╠══════════╬═══════╣
║ 1 ║ black ║
║ 1 ║ black ║
║ 2 ║ red ║
║ 2 ║ black ║
║ 3 ║ red ║
║ 3 ║ red ║
║ 3 ║ red ║
║ 4 ║ black ║
║ 5 ║ black ║
║ 5 ║ green ║
║ 6 ║ purple║
╚══════════╩═══════╝
I want to select the "duplicates" means the following customers:
- with more than one black
- one black and other red would be also an duplicate
- no duplicate: customer can have as many reds as he want
What I have so far
Currently what I can select is only about the black duplicates but I can not combine it wiht the condition "one black, no more red".
SELECT customer FROM events WHERE
color = 'black'
group by customer
having count(*) > 1
Maybe I could first count the blacks and than join again with the existing table count the additional blacks and reds?
Desired Output
I would like to have the following result as customers: 1,2. Even better would be an output where I know if customer was a double black or a black + some reds:
╔══════════╦═══════════╦══════════════╗
║ customer ║ blackOnly ║ blackPlusRed ║
╠══════════╬═══════════╬══════════════╣
║ 1 ║ yes ║ no ║
║ 2 ║ no ║ yes ║
╚══════════╩═══════════╩══════════════╝
Sorry had to modify my post
- I added customer 5 and 6 in example table and more colors. So maybe some suggestions does not work anymore :-(. (Just want to edit fast, so If I didn't follow some modifying rules, just tell me)
- Thanks for the very fast answers already so far