I have a complex query and fetches rows of textual data. This part works fine. I would like to include a count of rows returned, so that exported spreadsheet is easier to filter.
So assuming we have a query of this sort:
SELECT
TRIM(COL_1 || ' (' || COL_2 || ')') AS MY_DATA
FROM
TABLE_1
INNER JOIN TABLE_2...
WHERE
TABLE_1.COL_1=...
ORDER BY
TABLE_1.COL_1
I can do:
SELECT * FROM (quoted query)
and it gives me the result set.
I can do:
SELECT MY_DATA FROM (quoted query)
and it gives me the result set.
I can do:
SELECT COUNT(MY_DATA) FROM (quoted query)
and it gives me the row count.
But when I try:
SELECT COUNT(MY_DATA), MY-DATA FROM (quoted query)
I get
ORA-00937: not a single-group group function
Using Oracle 11, can I select both the row count and row details from a subselect? The subselect in my case is complex and I do not want to duplicate it to get count and details separately. I tried WITH/AS
but ran into the same error.
====
Note: this is not a duplicate of suggested question - I do not use any grouping in my case. It's not a grouping issue - just a misleading error message.