must appear in the GROUP BY clause or be used in an aggregate function

Yes, this is a common aggregation problem. Before SQL3 (1999), the selected fields must appear in the GROUP BY clause[*]. To workaround this issue, you must calculate the aggregate in a sub-query and then join it with itself to get the additional columns you’d need to show: But you may also use window functions, which looks simpler: The … Read more

MySQL: Invalid use of group function

You need to use HAVING, not WHERE. The difference is: the WHERE clause filters which rows MySQL selects. Then MySQL groups the rows together and aggregates the numbers for your COUNT function. HAVING is like WHERE, only it happens after the COUNT value has been computed, so it’ll work as you expect. Rewrite your subquery as:

Oracle SELECT TOP 10 records

You’ll need to put your current query in subquery as below : Oracle applies rownum to the result after it has been returned.You need to filter the result after it has been returned, so a subquery is required. You can also use RANK() function to get Top-N results. For performance try using NOT EXISTS in place of NOT IN. See this for more.