I would like to group concatenate a categorical variable. Example:
pat x
1 a
1 b
1 b
2 a
2 a
The group concatenating should result in:
pat y
1 a-b-b
2 a-a
In Mysql this would be done using group_concat:
SELECT pat, GROUP_CONCAT(x SEPARATOR '-') y FROM tb GROUP BY pat
Also it would be nice if the function could concatenate distinct ordered values. With above example the output should be:
pat y
1 a-b
2 a
With MySQL:
SELECT pat, GROUP_CONCAT(DISTINCT x ORDER BY x SEPARATOR '-') y FROM tb GROUP BY pat