Fix SQL exception getting statitics with metaquery

In the scenario with mysql as storage backend, when getting statistics
with metaquery, sqlalchemy will raise an exception of "Unknown column
'sample.id' in 'on clause'", this is because of a wrong usage of JOIN
clause.

Change-Id: I6f140952082ab245f27d576ee9629a086104f8b1
Closes-bug: #1332673
Merge "Fix SQL exception getting statitics with metaquery"