I have a table of Client and Product(that the client purchased)
Client | Product |
---|---|
Alex | A |
Alex | B |
Alex | C |
Alex | D |
Peter | A |
Peter | B |
Peter | C |
Aline | C |
Aline | D |
Aline | E |
Aline | F |
Aline | G |
Joao | B |
Joao | C |
Joao | D |
Joao | E |
Nikky | A |
Nikky | B |
Nikky | C |
I want to know the most common combination of 3 products that the client purchased, like this table, the final result will be "A,B,C"
Since it happened 3 times (Alex, Peter, Nikky)
2
Answers
Assuming the sample data you provided is from the
Client_Product
table. Here’s how you can achieve this.PS: feel free to rename the table name according by replacing
Client_Product
if it is different from your table name.This is just a "finished" version of Selaka’s answer.
Here’s a db<>fiddle.