A B C D
12426 4 1 KT1217V
12426 4 1 KT1218V
12428 3 1 KT1217V
12428 3 1 KT1218V
12430 3 1 KT1217V
12430 3 1 KT1218V
12431 3 1 KT1217V
12431 3 1 KT1218V
12434 3 1 KT1217V
12434 3 1 KT1218V
12439 8 1 KT1217V
12439 8 1 KT1218V
12440 1 1 KT1217V
12440 1 1 KT1218V
12442 8 1 KT1217V
12442 8 1 KT1218V
12443 8 1 KT1217V
12443 8 1 KT1218V
我正在寻找这样的结果:
KT1217V 12426,12428 .....
KT1218 12426,12428,12431
KT1218 12434,12439
till value of column b sum <如果总和大于5,则为5显示保留相同值的新记录其中c>
我编写的查询是为了获取value <或> sum(列B),但无法显示相同的新记录,列A对列D的剩余值或>
select D,
(select a.A+',' from table1 a where a.D = b.D for XML PATH ('') )
from table1 b
WHERE c = 1
group by D
HAVING SUM(B)<5
ORDER BY D
您需要使用LISTAGG(),类似SELECT A, LISTAGG(D, ',') WITHIN GROUP (ORDER BY D). Oracle中没有a.A+','或XML PATH(")…