Hi,
Selecting people in groups of 3 with unique nationality, so that each group cannot have people with the same nationality.
With the following example dataset:
INSERT INTO StudyOverSeas (id, name, nationality)
VALUES ('1234567', 'steve', 'Australia'),
('1234568', 'stuart', 'Japan'),
('1234569', 'alix', 'Australia'),
('1234561', 'heather', 'China'),
('1234562', 'john', 'Sweden'),
('1234563', 'julie', 'Africa'),
('1234564', 'tracy', 'Africa')
I am looking for an output that looks like this:
id, name, nationality, group
1234567, steve, Australia, 1
1234568, stuart, Japan, 1
1234561, heather, China, 1
1234569, alix, Australia, 2
1234562', john, Sweden, 2
1234563, julie, Africa, 2
1234564, tracy, Africa, 3
id is unique and it doesn't matter what order they are in, for example here is another example:
1234567, steve, Australia, 1
1234568, stuart, Japan, 1
1234563, julie, Africa, 1
1234564, tracy, Africa, 2
1234562', john, Sweden, 2
1234561, heather, China, 2
1234569, alix, Australia, 3
Regards
Steve