Your code makes sense but the result is "0".

Put your code in the project and replace the SQL statment and see the value!

Strange