I have created three column with case function . one is full delivery, another is partial and last one is no delivery. I got the correct result for full and no delivery. But the problem is when i got result for partial delivery it also included no delivery results . Can anyone tell me what is the right query for getting only partial delivery
With Without_Duplicate As
(select ordernumber , supplname, supplemail, sku,orderqty,
Qtyreceived, estimateddelivery,
createemp, status ,
ROW_NUMBER() over (partition by ordernumber order by estimateddelivery desc)
As Rn from analytics.SupplierOrders)
SELECT supplname, estimateddelivery, DATE_DIFF(CAST (CURRENT_DATE AS DATE), CAST ((estimateddelivery) AS DATE), DAY ) AS exceed_days ,
createemp, status ,COUNT (ordernumber) as total_order_from_supplier,
SUM (CASE WHEN qtyreceived = orderqty THEN 1
Else 0
End ) as Full_delivery,
SUM(Case WHEN qtyreceived < orderqty THEN 1
else 0
End ) as Partial_delivery,
SUM(Case WHEN qtyreceived = 0 THEN 1
else 0
End ) as N0_delivery
from Without_Duplicate
Where Rn = 1 and
status = "BES"
GROUP by supplname, estimateddelivery, createemp, status