How to make a count in Mysql using the case or if?

1

I need to know how I can do a search in mysql to know how many documents I have to parse with a condition that if the previous process is not released it can not count.

SELECT COUNT('num'),
        CASE  WHEN ('pl_de_manutencao' = 'Liberado' || 'pl_de_manutencao' = 'N/A'
            AND 'ra_padrao' != 'Liberado' || 'ra_padrao' != 'N/A') 
        THEN COUNT('num') END AS 'Count' 
FROM 'ind_master_view'

something like this code.

    
asked by anonymous 17.08.2016 / 20:37

1 answer

1

If this is what I understand, you have to use COUNT () before the case with an increment of 1 if the condition is true.

SELECT COUNT(CASE  WHEN (pl_de_manutencao = 'Liberado' || pl_de_manutencao = 'N/A' 
                        AND ra_padrao != 'Liberado' || ra_padrao != 'N/A') 
                    THEN 1  -- caso a condição seja verdadeira .
            END) AS Total
FROM ind_master_view

    
17.08.2016 / 21:03