Subquery With Aggregate Function In Sql