没有 GROUP BY 表达式的 Group by Clause 错误
Posted
技术标签:
【中文标题】没有 GROUP BY 表达式的 Group by Clause 错误【英文标题】:Group by Clause erroring with not a GROUP BY expression 【发布时间】:2021-04-01 00:37:21 【问题描述】:我有以下代码,
Select
pro.tariff_code as CommodityCode,
'1000001' AS ProcedureCode,
pro.long_description_1 as Description,
sum(ph.weight + 0.2) as GrossWeight,
sum(ph.weight) as NetWeight,
sum(Si.net_price) as ItemUnitPrice,
ed.data_text as Countryoforigin,
sum(si.despatched_qty) as ItemQuantity,
'PC' as Packagedcode,
'LIC99' as Licence
from
package_header ph
left join despatch_header dc on ph.despatch_num = dc.despatch_num
left join package_product pp on ph.despatch_num = pp.despatch_num
left join sales_header sh on pp.sales_document_num = sh.sales_document_num
left join sales_item si on sh.sales_document_num = si.sales_document_num
left join product pro on si.product_code = pro.product_code
left join entity_data ed on field_name = 'CountryOfOrigin' and Entity_name = 'Product' and entity_key1 = pro.product_code
WHERE trunc(date '1970-01-01' + ph.change_date * interval '1' second) = trunc(sysdate) and sh.SALES_OFFICE = 'MSUK'
Group by pro.tariff_code, '1000001', pro.long_description_1
我收到一个错误提示
ORA-00979: 不是 GROUP BY 表达式
任何帮助表示赞赏。
【问题讨论】:
您通常GROUP BY
与您 SELECT
相同的列,除了那些是设置函数的参数的列。
即试试GROUP BY pro.tariff_code, pro.long_description_1, ed.data_text
看看会发生什么。
感谢 Jarlh,工作愉快
【参考方案1】:
SELECT
子句的所有非聚合列必须在 group by
子句中重复。您的代码在 group by
子句中缺少 ed.data_text
- 或者应该从 select
子句中删除。
select
pro.tariff_code as CommodityCode,
'1000001' AS ProcedureCode,
pro.long_description_1 as Description,
sum(ph.weight + 0.2) as GrossWeight,
sum(ph.weight) as NetWeight,
sum(Si.net_price) as ItemUnitPrice,
ed.data_text as Countryoforigin,
sum(si.despatched_qty) as ItemQuantity,
'PC' as Packagedcode,
'LIC99' as Licence
from
package_header ph
left join despatch_header dc on ph.despatch_num = dc.despatch_num
left join package_product pp on ph.despatch_num = pp.despatch_num
left join sales_header sh on pp.sales_document_num = sh.sales_document_num
left join sales_item si on sh.sales_document_num = si.sales_document_num
left join product pro on si.product_code = pro.product_code
left join entity_data ed on field_name = 'CountryOfOrigin' and Entity_name = 'Product' and entity_key1 = pro.product_code
WHERE ph.change_date >= (trunc(sysdate) - date '1970-01-01') * 60 * 60 * 24
AND ph.change_date < (trunc(sysdate) - date '1970-01-01' + 1) * 60 * 60 * 24
AND sh.SALES_OFFICE = 'MSUK'
Group by pro.tariff_code, pro.long_description_1, ed.data_text
请注意,我更改了日期的过滤以使其成为 SARGeable。
【讨论】:
@ChristopherJack 。 . .那么你应该接受答案。以上是关于没有 GROUP BY 表达式的 Group by Clause 错误的主要内容,如果未能解决你的问题,请参考以下文章