Mysql
 SQL >> Database >  >> RDS >> Mysql

Raggruppare campi in MySQL

Se vuoi combinare colori e immagini:

SELECT v_ebt,
       CONCAT("color: ", colors, "; image: ", image) AS Data
FROM table;

Per ottenere tutti i dati in una colonna e ordinare per identificatore comune:

SELECT 1 AS Srt, v_ebt AS Grp, v_ebt AS Data
FROM docs
UNION
SELECT 2, v_ebt, CONCAT("color: ", colors, ", image: ", image)
FROM docs
ORDER BY Grp, Srt;

Per concatenare più righe in una stringa, esplora GROUP_CONCAT:

SELECT v_ebt,
       GROUP_CONCAT(
         CONCAT("color: ", colors, ", image: ", image, Char(10), Char(13))
         ORDER BY CONCAT("color: ", colors, ", image: ", image)
       ) AS list
FROM table
GROUP BY v_ebt;

In alternativa, crea un report che ordini e raggruppi per v_ebt.