Cleanup queries for the history/trends tables