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:

What is the definition of cardinality in SQL

They are speaking the same thing and it has to do with tuples (relational algebra) or rows (layman’s term). When it says high-cardinality are possible values of particular attribute (or field) that are unique and therefore the number of rows or tuples are higher: Example: As far as as StudentID the cardinality is high because it is unique. In this it … Read more

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.

SQL not a single-group group function

Well the problem simply-put is that the SUM(TIME) for a specific SSN on your query is a single value, so it’s objecting to MAX as it makes no sense (The maximum of a single value is meaningless). Not sure what SQL database server you’re using but I suspect you want a query more like this … Read more

How do I limit the number of rows returned by an Oracle query after ordering?

Starting from Oracle 12c R1 (12.1), there is a row limiting clause. It does not use familiar LIMIT syntax, but it can do the job better with more options. You can find the full syntax here. (Also read more on how this works internally in Oracle in this answer). To answer the original question, here’s the query: (For earlier Oracle versions, please … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)