Answer the question
In order to leave comments, you need to log in
How to group by three fields in SQL Oracle if you need to get 10 fields in SELECT?
It is necessary in the query, where 10 fields are selected in SELECT, to group by 3 fields in order to count the number of record clones for these three fields. Is it in principle possible?
Of course, I understand that Oracle will not understand from which record to display data on fields that are not in group by, and therefore swears. For example, MySQL does not pay attention to such a thing.
Answer the question
In order to leave comments, you need to log in
MySQL is the only DBMS that does this wrong, and this is cured by setting sql_mode to ONLY_FULL_GROUP_BY. Wrap GROUP BY in a subquery and select the missing fields with an external SELECT, or use window functions :
SELECT
name,
lastname,
count(*) OVER (PARTITION BY group_col1, group_col2, group_col3),
FROM table
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question