下面的SQL查询有效...但是,当我添加“ FreightCostsPerOrderSplit”字段(3个新字段)时,出现以下所示的ORA-01747错误消息。这些约定类似于之前在SQL代码中所做的约定,我不确定是什么导致了此错误消息。
第49行错误 ORA-01747:无效的user.table.column,table.column, 或列规范
在我发布此问题时,我想出了解决方案。我决定将此答案发布给可能遇到相同问题的其他人。
解决方案涉及在计算字段的除数中将
COUNT(OHH.*)
替换为COUNT(OHH.FieldName)
。有关count(*) vs count(column-name)
语法的评论,请参见答案部分。
, (SUM(cteLoadFreightAgg.TOTALFREIGHT)/ COUNT(OHH.*)) AS "TotalFreight_SplitPerOrder"
/* A list of aggregated freight carrier data grouped by LOAD (no BILLTOCUST)
Pulled from [LOAD_CARRIER] table. Another option is [FRT_LOAD] which include LUMPER
SOURCE: Loads Underutilize Report
*/
cteLoadFreightAgg AS
(
SELECT
LOAD_CARRIER.LOAD_SEQ_CODE AS LoadNumber
, SUM(LOAD_CARRIER.FLAT_FRT + LOAD_CARRIER.FUEL_FRT + LOAD_CARRIER.DROP_FRT + LOAD_CARRIER.MISC_FRT + LOAD_CARRIER.OUT_ROUTE_FRT + LOAD_CARRIER.LAYOVER_FRT) AS TotalFreight
, SUM(LOAD_CARRIER.DROP_FRT + LOAD_CARRIER.MISC_FRT + LOAD_CARRIER.OUT_ROUTE_FRT + LOAD_CARRIER.LAYOVER_FRT) AS AssessorialsFreight
, SUM(LOAD_CARRIER.FLAT_FRT) AS FlatRateFreight
, SUM(LOAD_CARRIER.FUEL_FRT) AS FuelFreight
FROM
LOAD_CARRIER
GROUP BY
LOAD_CARRIER.LOAD_SEQ_CODE
)
SELECT
OHH.BILL_COMP_CODE
, LOAD.DEPART_FROM_WHSE_CODE
, OHH.SHIP_FROM_WHSE
, OHH.ORDER_SEQ_CODE
, OHH.LOAD_SEQ_CODE
, OHH.SHIP_DATE
, CARRIER.NAME AS CarrierName
, OHH.DELIVERY_DATE
, CUST.CUST_CODE || '-' || CUST.CUST_SHIPTO_CODE AS ShiptoCustCode
, CUST.NAME AS ShiptoName
, OHH.BILL_PO_ID
, CUST.CITY
, CUST.STATE_CODE
, LOAD.TALLY_DATE_TIME
, OHH.APPT_DATE
, OHH.APPT_TIME
, OHH.EST_PALLETS
, OHH.EST_GROSS_WGT
, OHH.EST_NET_WGT
, LOAD.CLASS_CODE
, SUM(ODH.WEIGHT_SHIPPED) AS "SUM_ODH_WeightShipped"
-- FreightCostLoad
, cteLoadFreightAgg.TOTALFREIGHT
, cteLoadFreightAgg.FUELFREIGHT
, (cteLoadFreightAgg.TOTALFREIGHT - cteLoadFreightAgg.FUELFREIGHT) AS "OTHERFREIGHT"
-- FreightCostsPerOrderSplit
, (SUM(cteLoadFreightAgg.TOTALFREIGHT)/ COUNT(OHH.*)) AS "TotalFreight_SplitPerOrder"
, (SUM(cteLoadFreightAgg.FUELFREIGHT) / COUNT(OHH.*)) AS "FuelFreight_SplitPerOrder"
, ((SUM(cteLoadFreightAgg.TOTALFREIGHT) - SUM(cteLoadFreightAgg.FUELFREIGHT))/ COUNT(OHH.*)) AS "OtherFreight_SplitPerOrder"
FROM
ROCCO.CARRIER CARRIER
INNER JOIN ROCCO.LOAD_CARRIER LOAD_CARRIER
ON CARRIER.CARRIER_CODE = LOAD_CARRIER.CARRIER_CODE
INNER JOIN ROCCO.ORD_HDR_HST OHH
ON LOAD_CARRIER.LOAD_SEQ_CODE = OHH.LOAD_SEQ_CODE
INNER JOIN ROCCO.ORD_DTL_HST ODH
ON OHH.ORDER_SEQ_CODE = ODH.ORDER_SEQ_CODE
INNER JOIN ROCCO.LOAD LOAD
ON OHH.LOAD_SEQ_CODE = LOAD.LOAD_SEQ_CODE
INNER JOIN ROCCO.CUSTOMER_SHIPTO CUST
ON OHH.CUST_CODE = CUST.CUST_CODE
AND OHH.CUST_SHIPTO_CODE = CUST.CUST_SHIPTO_CODE
INNER JOIN cteLoadFreightAgg
ON LOAD.LOAD_SEQ_CODE = cteLoadFreightAgg.LOADNUMBER
WHERE
-- OHH.SHIP_DATE BETWEEN :paramStartDate AND :paramEndDate
-- AND OHH.STATUS_CODE<>'DL'
-- AND OHH.BILL_COMP_CODE IN (:paramCompany)
-- AND LOAD.DEPART_FROM_WHSE_CODE IN (:paramWarehouse)
-- AND OHH.MASTER_ORDER_NBR IS NULL
-- AND LOAD.CLASS_CODE IN (:paramClassCode)
-- AND CUST.CUST_CODE || '-' || CUST.CUST_SHIPTO_CODE IN (:paramShipto)
-- /*
OHH.SHIP_DATE BETWEEN TO_DATE('10/1/2018', 'MM/DD/YYYY') AND TO_DATE('10/31/2018', 'MM/DD/YYYY')
AND OHH.STATUS_CODE<>'DL'
AND OHH.BILL_COMP_CODE=100
AND OHH.MASTER_ORDER_NBR IS NULL
-- */
GROUP BY
OHH.BILL_COMP_CODE
, LOAD.DEPART_FROM_WHSE_CODE
, OHH.SHIP_FROM_WHSE
, OHH.ORDER_SEQ_CODE
, OHH.LOAD_SEQ_CODE
, OHH.SHIP_DATE
, CARRIER.NAME
, OHH.DELIVERY_DATE
, CUST.CUST_CODE || '-' || CUST.CUST_SHIPTO_CODE
, CUST.NAME
, OHH.BILL_PO_ID
, CUST.CITY
, CUST.STATE_CODE
, LOAD.TALLY_DATE_TIME
, OHH.APPT_DATE
, OHH.APPT_TIME
, OHH.EST_PALLETS
, OHH.EST_GROSS_WGT
, OHH.EST_NET_WGT
, LOAD.CLASS_CODE
, cteLoadFreightAgg.FUELFREIGHT
, cteLoadFreightAgg.TOTALFREIGHT
ORDER BY
OHH.SHIP_DATE
*
Error at line 49
ORA-01747: invalid user.table.column, table.column, or column specification
答案 0 :(得分:0)
最初我的计算字段为:
, (SUM(cteLoadFreightAgg.TOTALFREIGHT)/ COUNT(OHH.*)) AS "TotalFreight_SplitPerOrder"
。
对于所有3个计算字段,我将除数字段更改为引用特定字段,并且错误消息已解决。然后,一旦语法成功解析,SSRS报告就会给出“ #VALUE”错误消息,而我不得不使用CAST()函数来获得正确的评估,而不是SSRS报告中的错误消息。
, CAST((cteLoadFreightAgg.TOTALFREIGHT/ COUNT(OHH.ORDER_SEQ_CODE) OVER(PARTITION BY OHH.LOAD_SEQ_CODE)) AS NUMERIC(9,2)) AS "TotalFreight_SplitPerOrder"
因此,在解决了原始错误消息之后,我然后发现我应该执行WINDOWING函数以按照报告要求所指定的值对值进行划分。
我在线阅读一些答案,以回答“为什么COUNT(*)给出错误消息时,COUNT(FieldName)求值?”。我遇到了一些博客文章,但它们主要是关于性能问题,而不是行计数划分或我收到的此错误消息。