Consolidate all columns in only one row MYSQL

0

I'm trying to make a query that aggregates all the results in a single line, ie, does not bring duplicate results. I've already used distinct and group by but none of the two returned me what I need. My query is as follows:

SELECT TICKET, DATAHORA, TIPO, ESTADO, CRITICIDADE, LOGIN, PARECER, INFOPEND, PROP, DATAPROP, PREV, SRD, PROT, REAB, PRIENC
FROM (
    SELECT DISTINCT TC.TN TICKET, TC.CREATE_TIME DATAHORA,  TT.NAME TIPO, TS.NAME ESTADO, TP.NAME CRITICIDADE, US.LOGIN LOGIN,
    CASE  
        WHEN TH.NAME LIKE  '%PARECER%' THEN RIGHT(TH.NAME, POSITION('%' IN REVERSE(TH.NAME))-1)
        ELSE ''
        END PARECER,
    CASE  
        WHEN TH.NAME LIKE  '%INFORMACOESPENDENTES%' THEN RIGHT(TH.NAME, POSITION('%' IN REVERSE(TH.NAME))-1)
        ELSE ''
        END INFOPEND,
    CASE  
        WHEN AR.A_SUBJECT LIKE  '%ATUALIZAÇÃO PROPRIETÁRIO%' THEN LEFT(AR.A_FROM, POSITION('<' IN (AR.A_FROM))-1)
        ELSE ''
        END PROP,
    CASE  
        WHEN AR.A_SUBJECT LIKE  '%ATUALIZAÇÃO PROPRIETÁRIO%' THEN (AR.CREATE_TIME)
        ELSE ''
        END DATAPROP,
    CASE  
        WHEN TH.NAME LIKE  '%PREVISAOATENDIMENTO%' THEN RIGHT(TH.NAME, POSITION('%' IN REVERSE(TH.NAME))-1)
        ELSE ''
        END PREV,
    CASE  
        WHEN TH.NAME LIKE  '%SRD%' THEN RIGHT(TH.NAME, POSITION('%' IN REVERSE(TH.NAME))-1)
        ELSE ''
        END SRD,
    CASE  
        WHEN TH.NAME LIKE  '%PROTOCOLO%' THEN RIGHT(TH.NAME, POSITION('%' IN REVERSE(TH.NAME))-1)
        ELSE ''
        END PROT,
   CASE  
        WHEN TS.NAME LIKE  '%REABERTO' THEN (TS.NAME)
        ELSE ''
        END REAB,
   CASE 
        WHEN AR.A_SUBJECT LIKE 'FECHAR' THEN AR.CREATE_TIME
        ELSE ''
        END PRIENC

 FROM OTRS2.TICKET TC
 INNER JOIN OTRS2.TICKET_TYPE TT ON TC.TYPE_ID = TT.ID
 INNER JOIN OTRS2.TICKET_STATE TS ON TC.TICKET_STATE_ID = TS.ID
 INNER JOIN OTRS2.TICKET_PRIORITY TP ON TC.TICKET_PRIORITY_ID=TP.ID
 INNER JOIN OTRS2.USERS US ON TC.CREATE_BY=US.ID
 INNER JOIN OTRS2.TICKET_HISTORY TH ON TC.ID=TH.TICKET_ID 
 INNER JOIN OTRS2.ARTICLE AR ON TC.ID=AR.TICKET_ID
)A

This query is generating the following result:

However,Ineedtheticketnumbernottoberepeated,thatis,inarowitaddsallthecolumns.IfIusegroupbyticketthefollowinghappens:

With, group by ticket , it returns only one row, but column information (such as the column looks like) some! How can I put all information in one line? Thank you

    
asked by anonymous 18.07.2018 / 01:27

1 answer

0

I've seen something like this: where I use alias of the bank as d , tested on mysql

'select d.TICKET AS TICKET,group_concat(d.PARACER separator ', ') AS PARECER from banco d group by d.PARECER'

I'll have an exit like this:

+ --- + ----------------------------- +
| TICKET | --PARECER ----- +
+ --- + ----------------------------- +
| 201822 | kkkkkk, kkkkkkkk

+ ---- + ---------------------------- +

add the other desired columns in the same way

    
18.07.2018 / 15:57