D
D
Dmitry2020-01-06 10:43:23
MySQL
Dmitry, 2020-01-06 10:43:23

Can there be simple fields and fields with aggregate functions in one SQL query?

If I have a request text like

SELECT any_expr, SUM(field1), COUNT(field2) FROM any_table

does this mean that the any_expr field should be included in the GROUP BY in any case, or there may be cases when it should not?
I would like to make a script that would analyze the query and if there is at least one field in the field list containing aggregate functions, all other fields would be automatically added to the GROUP BY section,

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lazy @BojackHorseman MySQL, 2020-01-06
@dimoff66

the field must be either in a group by or under an aggregate function. alternative behavior is not standard

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question