English 中文(简体)
按报表SQL组
原标题:Group By Statement SQL

此选择语句给出的数数 :

- 同样的阴道

- 同样的猫Name

但有不同的销售额

Select p.CatCode, p.CatName, s.Sales_Amt
From A3_Dw_Prod p, A3_Dw_Sales s
Order By p.Dw_Prod_Id Desc;

I would Like to use Sum Function to add the these Categories and Group Them When I use Sum I get an Error

ORA-00979:不是按表达方式划分的组别

Select p.CatCode, p.CatName, Sum(s.Sales_Amt)
From A3_Dw_Prod p, A3_Dw_Sales s
Where p.Dw_Prod_Id = s.Dw_Prod_Id
Group By p.CatCode, p.CatName 
Order By p.Dw_Prod_Id Desc;
最佳回答

我认为p.Dw_Prod_Id Desc专栏不是按条款排列的。

问题回答

I think the problem arises as you have included the " p.Dw_Prod_Id" in the ORDER BY clause However, this column has not been selected in the main query so it creates problem Put in ORDER BY one of the columns that is in the select clause(p.CatCode, p.CatName)

您必须同时将您正在按 OR 条令分组使用的列进行选择 。

Select p.CatCode, p.CatName, p.Dw_Prod_Id, Sum(s.Sales_Amt)
From A3_Dw_Prod p, A3_Dw_Sales s
Where p.Dw_Prod_Id = s.Dw_Prod_Id
Group By p.CatCode, p.CatName,p.Dw_Prod_Id
Order By p.Dw_Prod_Id Desc, p.CatCode, p.CatName;




相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

How to make a one to one left outer join?

I was wondering, is there a way to make a kind of one to one left outer join: I need a join that matches say table A with table B, for each record on table A it must search for its pair on table B, ...

Insert if not exists Oracle

I need to be able to run an Oracle query which goes to insert a number of rows, but it also checks to see if a primary key exists and if it does, then it skips that insert. Something like: INSERT ALL ...

How can I store NULLs in NOT NULL field?

I just came across NULL values in NOT-NULL fields in our test database. How could they get there? I know that NOT-NULL constraints can be altered with NOVALIDATE clause, but that would change table s ...

Type reference scope

I m studying databases and am currently working on a object-relational DB project and I ve encountered a small problem with the number of possible constraints in an object table. I m using "Database ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

热门标签