每次运行查询时,我都会弹出语法错误。
错误是:
ORA-00937:不是单组组功能 00937. 00000 - "不是单组组功能"
以下是我的代码:
SELECT
d.*, >>>>SUM(L.ALLOCATED_QTY)<<<<
FROM
alc_item_loc l
RIGHT JOIN (
SELECT
c.*
FROM
store s,
(
SELECT
a.*,
b.location AS store_number
FROM
fdt_map_cluster_location b,
(
SELECT DISTINCT
ss.alloc_cluster_id,
ss.alloc_cluster_name,
ss.worksheet_id,
ss.sku
FROM
fdt_maptool_sas_data ss
WHERE
ss.sku IN (
1099866,
1099896,
1000898,
1000960,
1000988
)
AND ss.order_no IS NOT NULL
AND alloc_cluster_name NOT LIKE '%DC Cluster%'
GROUP BY
ss.alloc_cluster_id,
ss.alloc_cluster_name,
ss.worksheet_id,
ss.sku
) a
WHERE
b.cluster_id = a.alloc_cluster_id
AND b.location_type = 'S'
) c
WHERE
s.store = c.store_number
AND s.store_close_date IS NULL
AND s.district NOT IN (
997,
998,
999
)
AND s.store_open_date <= SYSDATE
) d ON l.item_id = d.sku
AND l.location_id = d.store_number
>>>GROUP BY xxxx <<<<<
正如您所看到的,错误是由于我有一个聚合函数(总和)而需要进行分组。
我的问题是我不知道是否需要将所有内容分组(D. *)或什么?
如果我确实需要将所有内容分组(D. *),那么我该如何正确地做到这一点?
我知道这是不正确的语法,但例如这就是我想要做的事情:
GROUP BY D.*
但我不知道如何分组这个???
感谢任何帮助!
PS:&#34;&gt;&gt;&gt; &LT;&LT;&LT;&#34;是否只显示我的错误所在。
答案 0 :(得分:0)
更好的方法是在子查询中进行分组:
SELECT
d.*, l._sum
FROM
alc_item_loc l
RIGHT JOIN (
select l.item_id, l.location_id, SUM(L.ALLOCATED_QTY) _sum from (
SELECT
c.*
....
....
....
AND s.store_open_date <= SYSDATE
)l
group by l.item_id, l.location_id
) d ON l.item_id = d.sku
AND l.location_id = d.store_number