Christian,
It's Khubaib's code. I just suggest what he must do not change everithing in his code except in my last suggestiom. because I don't know either what he wants to do that code is use only for example not for real. Sum is great what you want to SUM this records that matches the main WHERE, but what if you waht to SUM something complitely different? That's because I stayed on included (SELECT...).
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.