Fixing PPLNS target calculation on blockavg

This will fix #492 with PPLNS targets not taking the blocks in proper
order.
Using proper SQL query by @CaptainAK

Proposed fix did not work, using proper Query now.
Thank @CaptainAK for the fix!

Fixes #492
Merge pull request #494 from TheSerapher/issue-492

Issue 492