Oracle Group by statement Error

Source: Internet
Author: User

When I write an SQL statement today
Select sum (. plate), sum (. qty), sum (. qly),. materialtypeid, B. name, B. spec, from fw_eqpres_materialinventory a, fw_eng_material B where. materialtypeid = B. sysid
And B. name like '% XX %'
Group by a. materialtypeid
 
Prompt not a single group by function
 
But write
Select sum (. plate), sum (. qty), sum (. qly),. materialtypeid, B. name, B. spec from fw_eqpres_materialinventory a, fw_eng_material B where. materialtypeid = B. sysid
And B. name like: name
A. materialtypeid, B. name, B. spec
 
There is no error, so the relevant information is explained as follows:
 
Select state_cd, avg (sales) from customer group by state_cd;
 
Most people start to understand the meaning of the groupby statement, but it is often troublesome to use. Make sure that group by references the correct number of columns in each statement. It is prompted that when group by is used, the columns not used in the group by section must use the grouping function when the select part appears.
 
Ignore the problems that may occur when grouping functions are used. If the statement is executed:
 
Select last_name, state_cd, sum (sales) from customer
Group by last_name;
 
The following error is returned:
 
ERRORatline1:
ORA-00979: notaGROUPBYexpression
 
This is because the group by clause is not used in the state_cd table column, so the grouping function must be added. In other words, you must use the max (), min (), sum (), count (), or avg () functions. If you cannot find the appropriate grouping function for the specified table column, move the table column to the group by clause.

Related Article

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.