Fix broken statistics in sqlalchemy

When querying the samples for statistics calculations,
the filtering is done without joining the Sample table.
This patch fixes this.

Closes-Bug: #1289325
Change-Id: I45edc974a6c054d27ac33d5287f760bcff08cf91
Merge "Fix broken statistics in sqlalchemy"