我怎样才能得到:
pn | min max
------ | ------
ABC123 | 0,0
ABC123 | 1,1
ABC123 | 1,1
ABC123 | 1,1
要:
pn | min max
------ | -------
ABC123 | 3,3
这就是我现在所拥有的:
SELECT
PN_INVENTORY_LEVEL.PN,
PN_INVENTORY_LEVEL.MAXIMUM_STOCK || ',' || PN_INVENTORY_LEVEL.MINIMUM_STOCK AS MIN_MAX
FROM
PN_INVENTORY_LEVEL
WHERE ("PN_INVENTORY_LEVEL"."PN" = :PN)
答案 0 :(得分:5)
尝试使用
SELECT
PN_INVENTORY_LEVEL.PN,
Sum(PN_INVENTORY_LEVEL.MAXIMUM_STOCK) || ',' || sum(PN_INVENTORY_LEVEL.MINIMUM_STOCK) AS MIN_MAX
FROM
PN_INVENTORY_LEVEL
WHERE ("PN_INVENTORY_LEVEL"."PN" = :PN)
group by PN_INVENTORY_LEVEL.PN
答案 1 :(得分:0)
尝试
SELECT pn, SUM(min) as min, SUM(max) as max FROM PN_INVENTORY_LEVEL GROUP BY pn
答案 2 :(得分:0)
如果您将min_max
作为字符串添加到一列中,我相信这将是您的答案(将tab
替换为 您的表名 强>):
WITH
tab1 AS(
SELECT t.pn,
t.min_max,
INSTR(t.min_max, ',',1) POS
FROM tab t
),
tab3 AS
(
SELECT tt.pn,
SUBSTR(tt.min_max, 1,tt.pos-1) st,
SUBSTR(tt.min_max,tt.pos+1,LENGTH(tt.min_max)-tt.pos) nd
FROM tab1 tt
)
SELECT ttt.pn,
SUM(ttt.st) || ',' || SUM(ttt.nd) min_max
FROM tab3 ttt
GROUP BY ttt.pn
它给了我结果:
1 ABC123 3,3