Q:

Fix SQL Query with SELECT CASE / AND COUNT CASE

The following SQL query is not working, it returns error:
[42601] ERROR: subquery must return only one column Position : 50
I would need to fix it for a live project, and am having difficulties with it. 
SELECT CASE WHEN habilitation.actif IS TRUE THEN (SELECT vue_cdc_for_opera.libelle,
                                                          dt_bdd_produit.libelle_dt,
                                                          vue_cdc_for_opera.classe_ue,
                                                          vue_cdc_for_opera.code_cdc,
    COALESCE(vue_cdc_for_opera.signe_ue, vue_cdc_for_opera.signe_fr),
    COUNT(CASE WHEN cdc_postgresql.id = habilitation.id_cdc_postgresql THEN 1 ELSE 0 END) as operateurs
    )
        ELSE (SELECT vue_cdc_for_opera.libelle,
                      dt_bdd_produit.libelle_dt,
                      vue_cdc_for_opera.classe_ue,
                      vue_cdc_for_opera.code_cdc,
                      COALESCE(vue_cdc_for_opera.signe_ue, vue_cdc_for_opera.signe_fr))
        END
FROM vue_cdc_for_opera, cdc_postgresql, dt_bdd_produit, operateur, habilitation;

Any help is greatly appreciated. 

A:

Well it is very unclear what is you want to do but here it is what I can help you with: 
In this example if habilitation.actif is true then you will select count of... and if it is not then you will select value 0 for that row.  Please note that you have to use a group by when you use aggregation functions.  Also you need to connect this tables from your from clause in someway... for more serious help add more details in your question, data also...
SELECT vue_cdc_for_opera.libelle,
       dt_bdd_produit.libelle_dt,
       vue_cdc_for_opera.classe_ue,
       vue_cdc_for_opera.code_cdc,
       COALESCE(vue_cdc_for_opera.signe_ue, vue_cdc_for_opera.signe_fr),
       CASE WHEN habilitation.actif IS TRUE THEN 
            COUNT(CASE WHEN cdc_postgresql.id = habilitation.id_cdc_postgresql THEN 1 ELSE 0 END)
            else 0      
       END a
FROM vue_cdc_for_opera, cdc_postgresql, dt_bdd_produit, operateur, habilitation
group by vue_cdc_for_opera.libelle,
       dt_bdd_produit.libelle_dt,
       vue_cdc_for_opera.classe_ue,
       vue_cdc_for_opera.code_cdc,
       vue_cdc_for_opera.signe_ue, 
       vue_cdc_for_opera.signe_fr,
       habilitation.actif

