I have a table Information which is something like this:
ID From To Product Date
1 A B ProdA 2012-10-01
2 A B ProdA 2012-10-13
3 A B ProdB 2012-10-17
4 A B ProdC 2012-10-18
5 A C ProdB 2012-10-02
6 A C ProdC 2012-10-04
7 A C ProdD 2012-10-12
8 A C ProdE 2012-10-14
9 A D ProdA 2012-10-11
10 A D ProdA 2012-10-14
Let’s call the combination of From and To a relationship. So (A,B) and (A, C) are relationships.
What I need to do is to find those relationships sending/receiving different products within a week time period. So in the above example the query is supposed to return:
A B
A C
since these rows match:
2 A B ProdA 2012-10-13
3 A B ProdB 2012-10-17
4 A B ProdC 2012-10-18
5 A C ProdB 2012-10-02
6 A C ProdC 2012-10-04
7 A C ProdD 2012-10-12
8 A C ProdE 2012-10-14
I know I should start from SELECT ID, From, To, Product, Date FROM Information GROUP BY From, To but I have no idea what’s next. Any help please?
something like this perhaps: