Your query should be giving a error due to not haveing tt.paycode in the group by.There is nothing wrong with the query as far as methodolgy, just make sure you have proper index's, and depending on the amount of records in temptbl you may consider filtering the data first.select b.Name,a.PaymentId,a.salMon,*from (Select tt.PaymentId, tt.Paycode, Avg(sal) as [Range]from temptbl ttgroup by tt.PaymentId,tt.paycode) ainner Jointemptbl1 b on a.PaymentId = b.PaymentId
Success is 10% Intelligence, 70% Determination, and 22% Stupidity.\_/ _/ _/\_/ _/\_/ _/ _/- 881