Error Tip:
Message 8120, Level 16, State 1, line 2nd
The column ' Qiu.dbo.students.name ' in the select list is not valid because the column is not included in an aggregate function or a GROUP by clause.
Solution:
If the SELECT clause <select list> contains aggregate functions, GROUP by calculates the summary value for each group. When you specify GROUP by, each property name within any nonclustered expression in the select list should be included in the GROUP by list, or the group by expression must exactly match the picklist expression.
Error usage:
SELECT Name,sex,sum (age) from
[qiu].[ DBO]. [Students]
GROUP BY sex
Corrected after usage:
SELECT Name,sex,sum (age) from
[qiu].[ DBO]. [Students]
GROUP BY Sex,name
When using the GROUP BY clause, be sure to remember some of the following rules:
(1) cannot group by a column of a non-scalar primitive type, such as a group by text,image or bit type column
(2) Each column specified by select should appear in the GROUP BY clause unless an aggregate function is used for the column;
(3) cannot group by a column that does not exist in the table;
(4) You can use the WHERE clause to eliminate rows that do not meet the criteria before grouping;
(5) groups returned by using the GROUP BY clause do not have a specific order and can be specified by using the ORDER BY clause.
Use Qiu
Select Sex,avg-
students
GROUP by sex