Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql Group by子句错误,不是Group by表达式_Sql_Oracle_Datetime_Left Join_Aggregate Functions - Fatal编程技术网

Sql Group by子句错误,不是Group by表达式

Sql Group by子句错误,不是Group by表达式,sql,oracle,datetime,left-join,aggregate-functions,Sql,Oracle,Datetime,Left Join,Aggregate Functions,我有以下代码 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, e

我有以下代码

    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
子句中重复
SELECT
子句的所有非聚合列。您的代码在
group by
子句中缺少
ed.data\u 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
选择
作为商品代码的专业关税代码,
“1000001”作为程序代码,
pro.long_description_1作为说明,
总重量(ph值重量+0.2)等于总重量,
总重量(ph值重量)为净重,
总价(Si.净价)作为项目单价,
ed.data_文本作为原产国,
作为项目数量的总和(发货数量),
“PC”作为Packagedcode,
“LIC99”作为许可证
从…起
包装箱集管ph值
ph.dispatch\u num=dc.dispatch\u num上的左连接发送头dc
左连接包\u产品pp on ph.dispatch\u num=pp.dispatch\u num
左连接pp.sales\U document\U num=sh.sales\U document\U num上的sales\U页眉sh
左联合销售\项目si在sh.sales\u document\u num=si.sales\u document\u num上
左键连接si.product\U代码=pro.product\U代码上的product pro
左连接字段_name='CountryOfOrigin'上的实体_数据,实体_name='Product'和实体_key1=pro.Product_代码
其中ph.change_date>=(TRUC(系统日期)-日期'1970-01-01')*60*60*24
和博士变更日期<(TRUC(sysdate)-日期'1970-01-01'+1)*60*60*24
和sh.SALES_OFFICE='MSUK'
按专业关税代码分组,专业长描述1,编辑数据文本

请注意,我在日期更改了筛选以使其可用。

必须在
group by
子句中重复
SELECT
子句的所有非聚合列。您的代码在
group by
子句中缺少
ed.data\u 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
选择
作为商品代码的专业关税代码,
“1000001”作为程序代码,
pro.long_description_1作为说明,
总重量(ph值重量+0.2)等于总重量,
总重量(ph值重量)为净重,
总价(Si.净价)作为项目单价,
ed.data_文本作为原产国,
作为项目数量的总和(发货数量),
“PC”作为Packagedcode,
“LIC99”作为许可证
从…起
包装箱集管ph值
ph.dispatch\u num=dc.dispatch\u num上的左连接发送头dc
左连接包\u产品pp on ph.dispatch\u num=pp.dispatch\u num
左连接pp.sales\U document\U num=sh.sales\U document\U num上的sales\U页眉sh
左联合销售\项目si在sh.sales\u document\u num=si.sales\u document\u num上
左键连接si.product\U代码=pro.product\U代码上的product pro
左连接字段_name='CountryOfOrigin'上的实体_数据,实体_name='Product'和实体_key1=pro.Product_代码
其中ph.change_date>=(TRUC(系统日期)-日期'1970-01-01')*60*60*24
和博士变更日期<(TRUC(sysdate)-日期'1970-01-01'+1)*60*60*24
和sh.SALES_OFFICE='MSUK'
按专业关税代码分组,专业长描述1,编辑数据文本

请注意,我更改了日期的筛选,以使其可用。

您通常按照
分组
与选择
相同的列,但作为设置函数参数的列除外。尝试按pro.tariff\u code、pro.long\u description\u 1、ed.data\u text
分组,看看会发生什么。感谢Jarlh,这是一种治疗方法,您通常按
分组,与
选择的列相同,但那些是设置函数的参数的列除外。尝试
GROUP BY pro.tarriff\u code,pro.long\u description\u 1,ed.data\u text
看看会发生什么。谢谢Jarlh,有效治疗谢谢GMB,有效治疗treat@ChristopherJack . . . 那么你应该接受答案。谢谢GMB,a工程treat@ChristopherJack . . . 那么你应该接受答案。