Fix for purchase-log stats sql

Should fix issue #1526
Merge pull request #1527 from misulicus/patch-21

Fix for purchase-log stats sql