improved sql queries for dashboard