The column ' * * ' in the select list is not valid because the column is not included in an aggregate function or a GROUP by clause __ function

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.