I have an Oracle query, which has something to the effect of
Having Count(field) > (Long SQL statement that returns one row)
Both sides of the query work alone, but together I get a “not a group by” expression.
When replacing the long SQL statement with a number it works, but I assumed the two were equivalent if only one row is returned?
Edit
After doing some playing around I realized:
… Table T … Having Count(field) > (Long SQL statement with Table A Where A.field = T.field)
It works when I replace T.field with any of the specific options for T.field, but when I reference T.field specifically I get the same “not a group by expression”
should work ok.
should not work. A field (like
T.afield) that is not included in theGROUP BYlist, cannot be referenced inSELECT,HAVINGorORDER BYclauses. Only aggregate functions of that field can be referenced – you could haveWHERE A.somefield = MIN(T.afield)for example.