我在查询中遇到错误:
select
ES.SHPMNT_REF as "SHIPMENT REF",
listagg(OH.ONHAND_REF,' ')within group(order by ES.SHPMNT_REF) as "test",
SO.LOAD as "PORT OF LOADING",
SO.DSCHRG_CITY as "DEST"
from
BRDB.EXPORT_SHIPMENT ES
left outer join BRDB.EXPORT_SHIPPING_ORDERS SO on ES.SHPMNT_REF = SO.SHPMNT_REF
left outer join BRDB.EXPORT_ONHAND OH on ES.SHPMNT_REF = OH.SHPMNT_REF
where
ES.REVENUE_ID = 'G2402467'
and ES.SHIPMENT_TYPE in ('EDO','EHO')
group by ES.SHPMNT_REF
以下是我收到的错误:
在GROUP BY子句中未指定在SELECT子句,HAVING子句或ORDER BY子句中指定的以“ DSCHRG_CITY”开头的表达式,或者在具有列功能的SELECT子句,HAVING子句或ORDER BY子句中并且未指定GROUP BY子句。SQLCODE = -119,SQLSTATE = 42803,DRIVER = 4.19.49。 2)[代码:-727,SQL状态:56098]在隐式系统操作类型“ 2”期间发生错误。
我不确定为什么会这样,但是如果我删除了“ SO.LOAD”和“ SO.DSCHRG_CITY”,那么编码就可以了。我在做什么错了?
答案 0 :(得分:1)
不使用组
select
ES.SHPMNT_REF as "SHIPMENT REF",
listagg(OH.ONHAND_REF,' ')within group(order by ES.SHPMNT_REF) as "test",
min(SO.LOAD) as "PORT OF LOADING",
ming(SO.DSCHRG_CITY) as "DEST"
from BRDB.EXPORT_SHIPMENT ES
left outer join BRDB.EXPORT_SHIPPING_ORDERS SO on
ES.SHPMNT_REF = SO.SHPMNT_REF
left outer join BRDB.EXPORT_ONHAND OH
on ES.SHPMNT_REF = OH.SHPMNT_REF
where ES.REVENUE_ID = 'G2402467' and ES.SHIPMENT_TYPE in ('EDO','EHO')
group by ES.SHPMNT_REF
具有分组
select
ES.SHPMNT_REF as "SHIPMENT REF",
listagg(OH.ONHAND_REF,' ')within group(order by ES.SHPMNT_REF) as "test",
SO.LOAD as "PORT OF LOADING",
SO.DSCHRG_CITY as "DEST"
from BRDB.EXPORT_SHIPMENT ES
left outer join BRDB.EXPORT_SHIPPING_ORDERS SO on
ES.SHPMNT_REF = SO.SHPMNT_REF
left outer join BRDB.EXPORT_ONHAND OH
on ES.SHPMNT_REF = OH.SHPMNT_REF
where ES.REVENUE_ID = 'G2402467' and ES.SHIPMENT_TYPE in ('EDO','EHO')
group by ES.SHPMNT_REF, SO.Load, SO.DSCHRG_CITY