Error after add group by and aggregation functions通過向Oracle查詢添加組,並得到一個錯誤
該查詢運行,而無需通過聚合函數組和好。在我添加group和aggregate函數之後,它給了我這個錯誤。我是查詢的入門者。任何進展都會有所幫助。該公司正在使用Netsuite作爲ERP系統。 Netsuite正在使用Oracle數據庫。我正在使用ODBC連接到他們的數據庫。
Select to_number(to_char(Transactions.trandate, 'YYYY')) as Year,
to_number(to_char(Transactions.trandate, 'MM')) as Month,
NVL(Parent.name, Entity.name) as Customer,
Case
When Upper(Substr(Replace(Items.name,'.',''),1,4)) IN ('MEAL', 'BASE', 'BOLT', 'BITE', 'FUEL')
THEN Upper(Substr(Replace(Items.name,'.',''),1,4))
ELSE Items.name
END as Item,
Accounts.type_name as Account,
-sum(Transaction_lines.amount) as Sales
From Transactions
Left Join Transaction_lines ON Transactions.transaction_id=Transaction_lines.Transaction_id
Left Join Items ON Transaction_lines.item_id=Items.item_id
Left Join Accounts ON Transaction_lines.account_id=Accounts.account_id
Left Join Entity ON Transactions.entity_id=Entity.entity_id
Left Join Entity as Parent on Entity.parent_id=Parent.entity_id
Where transactions.trandate >= '2013-1-1'
and Transactions.transaction_type IN ('Invoice', 'Item Fulfillment', 'Cash Sale')
and Accounts.type_name IN ('Income', 'Expense', 'Cost of Goods Sold')
Group By
to_number(to_char(Transactions.trandate, 'YYYY')),
to_number(to_char(Transactions.trandate, 'MM')),
NVL(Parent.name, Entity.name),
Case
When Upper(Substr(Replace(Items.name,'.',''),1,4)) IN ('MEAL', 'BASE', 'BOLT', 'BITE', 'FUEL')
THEN Upper(Substr(Replace(Items.name,'.',''),1,4))
ELSE Items.name
END,
Accounts.type_name
Order By Year, Month, Customer, Item, Account
看起來像它不允許我編輯我的任務,一旦我發佈,圖片沒有顯示。這是錯誤。 DataSource.Error:ODBC:錯誤[42000] [NetSuite] [ODBC 64位驅動程序] [OpenAccess SDK SQL引擎]無效的SQL語法。選擇列表和排序方式的所有列應該已經設置了函數或者是GROUP BY子句的一部分。[10136] 詳細信息: DataSourceKind = Odbc DataSourcePath = dsn = Netsuite OdbcErrors =表 –
最好將錯誤添加爲文本而不是圖像。 – sstan
錯誤很明顯,您需要在組中添加與select中相同的非agregation列.... so'SELECT A,B,MAX(something),MIN(something)'need' GROUP A,B' –