W MySQL nie ma polecenia PIVOT, ale można je obejść — Podstawy tabeli przestawnej:wiersze do kolumny... , Tabele przestawne MySQL (przekształcanie wierszy w kolumny) .
W twoim przypadku możesz użyć czegoś takiego -
SELECT AppNo,
MAX(IF(code = 1, Location, NULL)) Location,
MAX(IF(code = 1, Department, NULL)) Department,
1 Code1,
MAX(IF(code = 2, Location, NULL)) Location,
MAX(IF(code = 2, Department, NULL)) Department,
2 Code2,
MAX(IF(code = 3, Location, NULL)) Location,
MAX(IF(code = 3, Department, NULL)) Department,
3 Code3,
MAX(IF(code = 4, Location, NULL)) Location,
MAX(IF(code = 4, Department, NULL)) Department,
4 Code4,
MAX(IF(code = 5, Location, NULL)) Location,
MAX(IF(code = 5, Department, NULL)) Department,
5 Code5
FROM <table name>
GROUP BY AppNo
PS Możesz uruchomić to zapytanie z zapisanej procedury.