我在自己的mySQL数据库上有以下查询:
SELECT
Evento,
Categoria,
Medaglia,
IF (MAX(`1912`) > 0, 'X', '') AS '1912',
IF (MAX(`1908`) > 0, 'X', '') AS '1908',
IF (MAX(`1904`) > 0, 'X', '') AS '1904',
IF (MAX(`1900`) > 0, 'X', '') AS '1900',
IF (MAX(`1896`) > 0, 'X', '') AS '1896'
FROM
(
SELECT
Evento,
Categoria,
Medaglia,
IF (Olimpiade = 1912, 1, 0) AS '1912',
IF (Olimpiade = 1908, 1, 0) AS '1908',
IF (Olimpiade = 1904, 1, 0) AS '1904',
IF (Olimpiade = 1900, 1, 0) AS '1900',
IF (Olimpiade = 1896, 1, 0) AS '1896'
FROM Olympics.ItalianAthletes
WHERE Sport='Athletics' and ItalianAthletes.Medaglia is not null
) AS Games
GROUP BY Evento, Categoria
ORDER BY Evento ASC, Categoria ASC
通过此查询,我得到了这个结果:
Evento Categoria Medaglia 1912 1908 1904 1900 1896
----------- --------- -------- ---- ---- ---- ---- ----
10000m Walk Men bronze X
800m Men silver X
我想获得的是以下结果:
Evento Categoria 1912 1908 1904 1900 1896
----------- --------- ---- ---- ---- ---- ----
10000m Walk Men bronze
800m Men silver
等等。我怎么能这样做?