Home > database > Predecessors to solve small problems
Predecessors to solve small problems
Time:10-01
The select s.s id, sname, count (cid), sum (score) from Student as s left join SC on s.s id=SC. Sid group by SC. Sid. There will be a ERROR 1055 (42000) : # 1 Expression of the SELECT list is not in GROUP BY clause and the contains nonaggregated column 'shop. The s.s id which is not functionally dependent on the columns in GROUP BY clause. This is incompatible with sql_mode=only_full_group_by But with this you can Select sname, r. * from (select the sid, count (cid), sum (score) from SC group by SC. Sid) as r left join Student as s on r.s id=s.s id; Why is this?
CodePudding user response:
Aggregation function, if the field is not statistical column, must be in the group by field
CodePudding user response:
Must want to group aggregation function, If written in the subquery, you don't need to add a layer of the select,
CodePudding user response:
- aggregation function in addition to and Group By using together with Over a window function with the use of Example -
The select s.s id, sname, Count (cid) over (partition by SC. Sid order by s.s id), The sum (score) over (partition by SC. Sid order by s.s id) The from Student as s left join SC on s.s id=SC. Sid