sql >> Database >  >> RDS >> Mysql

Combineer meerdere onderliggende rijen in één rij MYSQL zonder hardcoding of min/max-waarden

U kunt onderstaande query gebruiken-

SELECT a.PK , a.Name, a.Email, 
SUBSTRING_INDEX(GROUP_CONCAT(i.Image_Name),',',1) AS Image_name_1, 
IF((LENGTH(GROUP_CONCAT(i.Image_Name)) - LENGTH(GROUP_CONCAT(i.Image_Name SEPARATOR ''))) < 1,'',SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(i.Image_Name),',',2),',',-1)) AS Image_name_2, 
IF((LENGTH(GROUP_CONCAT(i.Image_Name)) - LENGTH(GROUP_CONCAT(i.Image_Name SEPARATOR ''))) < 2,'',SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(i.Image_Name),',',3),',',-1),',',-1)) AS Image_name_3, 
IF((LENGTH(GROUP_CONCAT(i.Image_Name)) - LENGTH(GROUP_CONCAT(i.Image_Name SEPARATOR ''))) < 3,'',SUBSTRING_INDEX(GROUP_CONCAT(i.Image_Name),',',-1)) AS Image_name_4 
 FROM `advertiser` a
    LEFT JOIN category  c ON a.PK = c. FK 
    LEFT JOIN images I ON a.PK = i.FK
    WHERE c.FK = 1
    GROUP BY a.PK, a.Name,a.Email;


  1. Hoe records te verkrijgen die alfanumerieke tekens + spaties bevatten

  2. Hoe jmeter te gebruiken om een ​​Oracle Stored Procedure te testen met het retourtype sys_refcursor?

  3. De webtoepassing [] lijkt een thread te hebben gestart met de naam [Abandoned connection cleanup thread] com.mysql.jdbc.AbandonedConnectionCleanupThread

  4. Controleer of de kolom bestaat, zo niet, voeg MySQL toe via PHP