from a table i want to create groups by 4 (players) different "Klasse" ordered by KW (strentgh) in one select query.CREATE TABLE valar_date
(id int AUTO_INCREMENT primary key NOT NULL, Name varchar(255), Klasse varchar(255), Resonanz int, KW int, Schaden int,
Discord tinytext, Anmeldung enum("true","false") DEFAULT "false", Ritual8er varchar(255), Ritual3er varchar(255),
Setitem varchar(255), Baum varchar(255), position VARCHAR(255) NULL, FULLTEXT(Name,Klasse))
Each group of 4 must NOT contain same "Klasse" and the next group have to be the next highest KW.
so grp1 contains "Klasse" = 1 "Kreuzritter", 1 "Zauberer", 1 "Dämonenjäger", 1 "Mönch" with the highest KW
grp2: contains "Klasse" = 1 "Dämonenjäger", 1 "Zauberer", 1 "Kreuzritter", 1 "Barbar" (2nd best KW constalation)
grpX can have any other constalation by "Klasse" but the next highest KW group
sqlfiddle example: complex grouping solution
explicit some "Klasse" should not grouping with other specific!
this can be done by edit:WHERE (CONCAT(Name)) NOT IN ("Zauberer")