Home:ALL Converter>Not a single-group group function on a case count in oracle

Not a single-group group function on a case count in oracle

Ask Time:2017-08-09T15:31:46         Author:Gabriel_ES

Json Formatter

I'm trying to adapt a query that works in MSSQL to Oracle, the query is much bigger (this part is just a field from a much bigger query) but I managed to reduce it so it looks simpler.

SELECT CASE WHEN COUNT(*) > 0 THEN COUNT(*) 
        ELSE (SELECT COUNT(*) FROM table2)
        END
FROM table1

The error I'm getting is:

ora-00937 not a single-group group function

Can someone tell me where's the problem or how can I redefine it?

Author:Gabriel_ES,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/45584268/not-a-single-group-group-function-on-a-case-count-in-oracle
NikNik :

You can try with this query:\n\nSELECT CASE WHEN (SELECT COUNT(*) FROM table1) > 0 then (SELECT COUNT(*) FROM table1)\n ELSE (SELECT COUNT(*) FROM table2)\n END\nFROM dual;\n\n\nIt is still ugly but it works :)\n\nUpdate:\n\nTo explain how it's working:\n\nWe have 2 cases:\n\n\nIf there are records in the table1 then show me how many records\nthere are\nIf the table1 is empty, then give me the number of records from the\ntable2\n\n\nDual is the dummy table.",
2017-08-09T07:54:42
yy