0
Talk personal! I am training a subselect with having using the MAX AND COUNT functions together, but Sqlserver is returning me an error called: "It is not possible to perform an aggregation function on an expression that contains an aggregation or sub-allowance."
I usually do the scripts in oracle sql Developer I don’t know if it’s some syntax error, can anyone help me? Below is the command executed:
select clfDescricao
from classificacaofiscal c, notafiscaleletronica n
where c.clfCFO = n.NFE_cnatOP
group by clfDescricao
having count(n.NFE_id) = (select max(count(n.NFE_id))
from classificacaofiscal c, notafiscaleletronica n
where c.clfCFO = n.NFE_cnatOP)
Try to explain what you want to get.
– anonimo
Which DB engine? You mention both SQL Server and Oracle. To facilitate playback of the problem, try creating a fiddle at http://sqlfiddle.com/
– tvdias
And as said before, explain what you want to get. Try not to focus on how you’re doing it. The error may be in the form of implementing what is desired. It does not seem to make sense to use
select max(count(n.NFE_id))
, for example.– tvdias
Testing:
select count(n.NFE_id)
from classificacaofiscal c, notafiscaleletronica n
where c.clfCFO = n.NFE_cnatOP
with your data and evaluate the result. Then check if it makes sense to use the max function in this select.– anonimo
Folks I’m doing the script on Oracle, I’m trying to answer the following question: ?
– IGOR DUARTE DE MATOS MADUREIRA
A solution would be to make a Count by grouping by CFOP, sort in descending order and catch only the first. In this case you may not get the complete information if there are more than one CFOP with the same amount. Another solution would be to take the Count in a subselect and the outermost select take the max over the subselect result.
– anonimo