SQL query to calculate Difference

You could also do this in scripting, something that may be helpful for you,