CONCAT WITH ERROR

Asked

Viewed 26 times

0

SELECT 

b.numero_contrato as name, CONCAT(
sum(CASE WHEN a.status = 'Concluida' THEN 1 ELSE 0 END) AS concluidas,
sum(CASE WHEN a.status = 'Recebida' THEN 1 ELSE 0 END) AS recebidas,
sum(CASE WHEN a.status = 'Autorizada' THEN 1 ELSE 0 END) AS autorizadas) as dados

fROM controle_contratos a, contratos b where a.id_contrato = b.id_contrato and b.ativo = 1 group by b.numero_contrato

#1583 - Incorrect Parameters in the call to Native Function 'CONCAT'

I couldn’t fix that mistake, please help.

  • https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_concat according to the documentation concat receives a comma-separated list of values, which is not supported in case. explain better what you want to do by concatenating sums of different values, it doesn’t make much sense that

1 answer

-1

In function CONCAT, you pass CONCAT(Parametro A, PArametro B, Parametro C.....) example: CONCAT(last_name, '''s job category is ') where will display:

Hall’s job Category is SA_REP'

Your select is trying to join COMPLETED , RECEIVED and AUTHORIZED.....

SELECT 

b.numero_contrato as name, CONCAT(
sum(CASE WHEN a.status = 'Concluida' THEN 1 ELSE 0 END) AS concluidas,
sum(CASE WHEN a.status = 'Recebida' THEN 1 ELSE 0 END) AS recebidas,
sum(CASE WHEN a.status = 'Autorizada' THEN 1 ELSE 0 END) AS autorizadas) as dados

fROM controle_contratos a, contratos b where a.id_contrato = b.id_contrato and b.ativo = 1 group by b.numero_contrato

I believe the sentence below will help you:

SELECT 
    NAME, SUM(CONCLUIDAS), SUM(RECEBIDAS), SUM(AUTORIZADAS) 

FROM (

    SELECT 
        b.numero_contrato as name,  
        CASE WHEN a.status = 'Concluida' THEN 1 ELSE 0 END as concluidas,
        CASE WHEN a.status = 'Recebida' THEN 1 ELSE 0 END AS recebidas,
        CASE WHEN a.status = 'Autorizada' THEN 1 ELSE 0 END AS autorizadas

    fROM 
        controle_contratos a, 
        contratos b 
    where
        a.id_contrato = b.id_contrato 
        and b.ativo = 1 

    group by b.numero_contrato
)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.