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

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

Python group by

Do it in 2 steps. First, create a dictionary. Then, convert that dictionary into the expected format. It is also possible with itertools.groupby but it requires the input to be sorted first. Note both of these do not respect the original order of the keys. You need an OrderedDict if you need to keep the … Read more

Using group by on multiple columns

Group By X means put all those with the same value for X in the one group. Group By X, Y means put all those with the same values for both X and Y in the one group. To illustrate using an example, let’s say we have the following table, to do with who is attending what subject at … Read more

Using group by on multiple columns

Group By X means put all those with the same value for X in the one group. Group By X, Y means put all those with the same values for both X and Y in the one group. To illustrate using an example, let’s say we have the following table, to do with who is attending what subject at … Read more