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