Table name Contractor
Contractor Table have columns “SlNo”(Auto increment), “Type”,“MaterialName”,“LoaNo”, “Quantity”
“Type” defined for two ‘Recieved’ and ‘Released’
“LoaNo”= defined mixed type number such as 23/s/2017-18 for Received or Released of material
SELECT COALESCE(“a”.“TotalRcvd” - “b”.“TotalReleased”, “a”.“TotalRcvd”) AS “Balance” FROM (SELECT “Type”,“MaterialName”,“LoaNo”, SUM(“Quantity”) AS “TotalRcvd”
FROM “Contractor” WHERE “Type” = ‘Recieved’ GROUP BY “MaterialName”, “LoaNo”,“Type”) “a” LEFT JOIN(SELECT"Type", “MaterialName”,“LoaNo”,SUM(“Quantity”) AS “TotalReleased” FROM “Contractor” WHERE “Type” = ‘Released’ GROUP BY “MaterialName”,“LoaNo”, “Type”) “b” ON (“a”.“MaterialName” = “b”.“MaterialName”) WHERE (“a”.“MaterialName” = “Contractor”.“MaterialName”))
I want to design sql query for checking balance in respect of received and released on material basis of “MaterialName”,“LoaNo”
help me solve out this sql