Please start any new threads on our new 
    site at https://forums.sqlteam.com.  We've got lots of great SQL Server
    experts to answer whatever question you can come up with.
    
        
            
                
                    
                        
                            
                                | Author | 
                                
                                 Topic  | 
                             
                            
                                    | 
                                         vpillai 
                                        Starting Member 
                                         
                                        
                                        3 Posts  | 
                                        
                                        
                                            
                                            
                                             Posted - 2012-03-13 : 11:40:14
                                            
  | 
                                             
                                            
                                            Hello,I'm trying to write a SQL code for a program that uses SQL. I'm trying to calculate the average of the recovery lengths and the average of the depths for 5 runs (R-1 to R-5, R-6 to R-10 etc) at a time (without weighting it). For example, I need the average of the recovery lengths and depth corresponding to Run numbers R-1 to R-5. I've included an image below. The table is called SAMPLE. I would like to display only the averages and I want to do this without adding additional columns to the table. Please let me know. Any kind of help would be appreciated. Thanks.Vinod | 
                                             
                                         
                                     | 
                             
       
                            
                       
                          
                            
                                    | 
                                     webguru11 
                                    Starting Member 
                                     
                                    
                                    2 Posts  | 
                                    
                                      
                                     | 
                                   
                            
                       
                          
                            
                                    | 
                                     russell 
                                    Pyro-ma-ni-yak 
                                     
                                    
                                    5072 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2012-04-10 : 12:08:23
                                          
  | 
                                         
                                        
                                          | [code]SELECT	Avg(depth) as avgDepth,	Avg(RecoveryLength) as avgRecoveryLengthFROM	YourTableWHERE	Convert(int, Replace([number], 'R-', '')) BETWEEN 1 and 5[/code]  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                            
                                | 
                                    
                                      
                                     
                                    
                                 | 
                             
                         
                     | 
                 
             
         |