To tylko projekcja. Nie aktualizuje tabeli ani nie usuwa niektórych danych.
SELECT MIN(ID) ID,
Username,
MAX(Red) max_Red,
MAX(Green) max_Green,
MAX(Yellow) max_Yellow,
MAX(Blue) max_Blue,
MAX(Orange) max_Orange,
MAX(Purple) max_Purple
FROM Colors
GROUP BY Username
AKTUALIZUJ
jeśli naprawdę chcesz usunąć te rekordy, musisz najpierw uruchomić instrukcję UPDATE, zanim będziesz mógł usunąć rekordy
UPDATE Colors a
INNER JOIN
(
SELECT MIN(ID) min_ID,
Username,
MAX(Red) max_Red,
MAX(Green) max_Green ,
MAX(Yellow) max_Yellow,
MAX(Blue) max_Blue,
MAX(Orange) max_Orange,
MAX(Purple) max_Purple
FROM Colors
GROUP BY Username
) b ON a.ID = b.Min_ID
SET a.Red = b.max_Red,
a.Green = b.max_Green,
a.Yellow = b.max_Yellow,
a.Blue = b.max_Blue,
a.Orange = b.max_Orange,
a.Purple = b.max_Purple
Następnie możesz teraz usunąć rekordy,
DELETE a
FROM Colors a
LEFT JOIN
(
SELECT MIN(ID) min_ID,
Username
FROM Colors
GROUP BY Username
) b ON a.ID = b.Min_ID
WHERE b.Min_ID IS NULL