0
The query below returns the sum of 24 accounts, using the ROLLUP
and without the clause HAVING
, so far so good, but when I use the clause HAVING
shortly after the ROLLUP
should return me the sum of 19 accounts, but continues to return me the sum of 24 accounts. How do I make the ROLLUP
bring me the right sum, regardless of any condition HAVING
?
Consultation without the clause HAVING
SELECT
ifnull(cust_id, 'Total') as ID_cliente,
count(account_id) as QTDE_de_contas
FROM account
GROUP BY
cust_id WITH ROLLUP
Consultation with the clause HAVING
SELECT
ifnull(cust_id, 'Total') as ID_cliente,
count(account_id) as QTDE_de_contas
FROM account
GROUP BY
cust_id WITH ROLLUP
HAVING
count(account_id) >= 2
"How do I make the ROLLUP bring me the right sum regardless of any condition" It doesn’t make sense, the
rollup
is based ongroup by
, which is filtered byhaving
, are totally dependent things, if you do not want thehaving
need to remove from query... would be like to select and want the results not to depend onwhere
– Ricardo Pontual
Hello Ricardo, I believe I did not make myself understood, when I run the query without the
HAVING
, query brings me a value, but when I use the filterHAVING
, the query keeps bringing me the same value and shouldn’t. That’s what I meant.– João Caetano