I have 2 tables and I want to count highest version per country for all users
Example:
John is from the USA, and he has versions 1,2,3,4,5 and 6
Bob is from France, and he has versions 1,2 and 3
Mary is from France too, and she has versions 1,2 and 3
I want to count just the last versions from anny of them
Becouse :
John has higher version 6 he won't be counted in versions lower than 6
Bob has higher version 3 he won't be counted in versions lower than 3
Mary has higher version 3 she won't be counted in versions lower than 3
So the final result will be as the Desired result set at bottom
Table1
ID | USER | COUNTRY
---- ----- ----------
1 | John | USA
2 | Bob | FRANCE
3 | Mary | FRANCE
Table2
ID | USER | VERSION
---- ------- ---------
1 | John | 1
2 | Bob | 1
3 | John | 2
4 | Mary | 1
5 | Mary | 2
6 | John | 3
7 | John | 4
8 | Bob | 2
9 | John | 5
10 | Bob | 3
11 | Mary | 3
12 | John | 6
Desired result set:
Country | V1| V2 | V3 | V4 | V5 | V6
-------- ---- --- ---- ---- ---- ----
USA | 0 | 0 | 0 | 1 | 1 | 1
FRANCE | 0 | 0 | 2 | 0 | 0 | 0
Please help me , thanks.