Sql query optimization

shape