Halo, saya punya Kueri SQL berikut yang menghasilkan hasil berikut
SELECT * FROM
(
Select
catalogid, numitems, allitems - numitems ignoreditems
from
(
select
i.catalogid,
case
when Exists(select paymentodate from payentmethodvalidation q where q.paymentnoodate = o.ocardtype) AND NOT EXISTS(SELECT booked FROM bookedordersids m where CAST(m.booked AS int)=o.orderid) then sum(i.numitems)
when Exists(select paymentodate from payentmethodvalidation q where q.paymentodate = o.ocardtype) AND odate is not null AND NOT EXISTS(SELECT booked FROM bookedordersids m where CAST(m.booked AS int)=o.orderid) then sum(i.numitems)
else 0 end numitems,
sum(numitems) allitems
from
"orders o
inner join
"oitems i
on
"i.orderid=o.orderid
inner join
"products T1
on
"T1.catalogid = i.catalogid
group by
"i.catalogid, ocardtype, odate,o.orderid
) A
) B
INNER JOIN
(
SELECT
catalogId,
ProcessedSucssessfully =
STUFF((SELECT ', ' + CAST( b.orderid as varchar(10))
FROM oitems b JOIN orders o ON b.orderid = o.orderid
WHERE b.catalogId = a.catalogId
AND NOT EXISTS(SELECT booked FROM bookedordersids m where CAST(m.booked AS int)=o.orderid) AND (Exists(select paymentodate from payentmethodvalidation q where q.paymentnoodate = o.ocardtype) OR Exists(select paymentodate from payentmethodvalidation q where q.paymentodate = o.ocardtype) and o.odate is not null)
FOR XML PATH('')), 1, 2, ''),
"NotProcessed =
STUFF((SELECT ', ' + CAST( c.orderid as varchar(10))
FROM oitems c JOIN orders o ON c.orderId = o.orderid
WHERE c.catalogid = a.catalogid
AND (o.ocardtype in ('mastercard') OR o.ocardtype is null) and o.odate is null
FOR XML PATH('')), 1, 2, '')
FROM
oitems a
GROUP BY
a.catalogid
)C
ON
B.catalogid = C.catalogid
hasil query ini dapat anda lihat pada gambar berikut
Anda melihat 2 baris yang dilingkari itu, saya ingin baris tersebut berada dalam satu baris yang hanya akan menjumlahkan angka, nilai berhasil diproses dan semua nilai lainnya akan selalu sama untuk catatan katalog berbagi jadi tidak ada masalah dengan mereka.
pada dasarnya baris hasil harus memiliki jumlah nilai numitem di semua baris yang memiliki katalogid yang sama
jadi bagaimana saya bisa mengatasi masalah ini?