I can not resolve this issue, I want it to show client numbers without primary key repeat, no business done, and show a warning if customers have business done. This error has appeared here.
CREATE FUNCTION sem_negocios() RETURNS integer AS
$$
SELECT count(*), CASE WHEN identidade NOT IN (SELECT DISTINCT identidade FROM negocio)
THEN 'negociado'
ELSE 'nao negociado'
END AS identidade
FROM cliente
GROUP BY CASE
WHEN identidade IN (SELECT DISTINCT identidade FROM negocio)
THEN 'negociado'
ELSE 'nao negociado'
END
ORDER BY identidade;
$$
LANGUAGE 'SQL';
ERROR: column "customer.identity" should appear in the GROUP BY clause or be used in an aggregate function LINE 3: SELECT count (*), CASE WHEN identity NOT IN (SELECT DISTINCT ... ^
********** Error **********
ERROR: column "customer.identity" should appear in the GROUP BY clause or be used in an aggregate function SQL state: 42803 Character: 83