我有这样一段代码:
(SELECT SELL_STR.SELL_STR_NBR, DATES.PSTD_FSCL_YR_WK, count(*) as WKLY_DLVRY--, WORK_ORD_NBR
from `analytics-df-thd.DFS.FACTS_DLY_DELV_STATS` A
inner join R1
on r1.FSCL_YR_WK = A.DATES.PSTD_FSCL_YR_WK
group by SELL_STR.SELL_STR_NBR, DATES.PSTD_FSCL_YR_WK
)
我需要将WORK_ORD_NBR添加到SELECT中,以便稍后可以连接它
select
WKLY_DLVRY.WKLY_DLVRY
...
from table1 a
join
WKLY_DLVRY
on WKLY_DLVRY.WORK_ORD_NBR = a.WORK_ORD_NBR
然而,当添加到WKLY_DLVRY时,我收到这个错误:
SELECT list expression references column WORK_ORD_NBR which is neither grouped nor aggregated at
我读了很多线程,他们没有给我很多选项,只建议WORK_ORD_NBR必须分组,但这改变了计数。谢谢你的帮助
你可以保留一个列,而不像下面这样分组。
更多信息请点击这里。
SELECT
count(*) as WKLY_DLVRY,
ARRAY_AGG(
STRUCT(WORK_ORD_NBR)
-- ORDER BY [column] DESC LIMIT 1 -- if you want to distinguish multiple values
)[OFFSET(0)].*,
FROM ~