SELECT
ID
, SUM(SELECT TD.MONEY FROM Pay AS TD WHERE TD.ID = TH.ID AND TD.Type = 'C' ) AS C_MONEY
, SUM(SELECT TD.MONEY FROM Pay AS TD WHERE TD.ID = TH.ID AND TD.Type = 'W' ) AS W_MONEY
, SUM(SELECT TD.MONEY FROM Pay AS TD WHERE TD.ID = TH.ID AND TD.Type = 'C' ) -
SUM(SELECT TD.MONEY FROM Pay AS TD WHERE TD.ID = TH.ID AND TD.Type = 'W' ) AS DIFF
FROM Pay AS TH
GROUP BY ID