added order to query
building histogram query string