Group data related to a column

0

I have the following code

    SELECT 
t2.conta_nome as operacao, t1.provedor_nome as operadora,
perfil, 
count(*) as total 

FROM asteriskcdrdb.cdr_tarifacao a 

INNER JOIN telefonia.provedor t1 ON a.operadora = t1.provedor_id 
INNER JOIN telefonia.conta t2 ON a.accountcode = t2.conta_id 
WHERE calldate >= Date_add(now(), interval -60 second)
GROUP by  operacao,operadora
ORDER by operadora 
LIMIT 50 

;

What it generates:

Operations | Operators

GFK OI | ALGAR

BMG BANK | EMBRATEL

IESDE | EMBRATEL

MONTREAL | EMBRATEL

RENAULT | EMBRATEL

BMG BANK | GVT

MONTREAL | GVT

I would like to know how to group all values highlighted to COLUMN OPERATORS

    
asked by anonymous 22.11.2014 / 15:10

1 answer

2

Use GROUP_CONCAT to merge information into one column. See the example below:

SELECT
   GROUP_CONCAT(cep.strcep) AS CEP,
   cidade.strnome
FROM Cidade
INNER JOIN cep ON cep.intcidadeid = cidade.intcidadeid
GROUP BY (cidade.strnome)

Your select should look like this:

SELECT
   GROUP_CONCAT(t2.conta_nome) AS operacao,
   t1.provedor_nome as operadora
FROM asteriskcdrdb.cdr_tarifacao a
INNER JOIN telefonia.provedor t1 ON a.operadora = t1.provedor_id
INNER JOIN telefonia.conta t2 ON a.accountcode = t2.conta_id
WHERE calldate >= Date_add(now(), interval -60 second)
GROUP by  operadora
LIMIT 50;

I hope I have helped

    
24.11.2014 / 13:03