Skip to content
Advertisement

Getting the result of sum / count with two different conditions

I’ve been trying to extract to average times (based on some criteria). I need to get two results. These two results are based on how many minutes between two times, divided by the quantity of registers in the table. So, it’s basically like this:

I need to extract the second result, and the only different value is “c.cd_setor_atendimento”, which is 66. I’ve tried using case when, but then it makes me group the results:

That gives me ORA-00937: not a single-group group function 00937. 00000 – “not a single-group group function”

Any tips to get these two values with different parameters? (I need to get then as separated values, so I can’t use UNION between two selects)

Thanks!

Advertisement

Answer

The concept of conditional aggregation, which you are trying to perform here, is to put the case expressions within the aggregate functions rather than around them – and the rest of your query remains unchanged:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement