views:

49

answers:

1

I start with a table looking like this...

+-------------------------+
| procName | TimeEnded    |
+-------------------------+
|        A | 04:00:00.000 |
|        B | 04:01:00.000 |
|        C | 04:03:00.000 |
|        A | 04:06:00.000 |
|        B | 04:10:00.000 |
|      ... |          ... |

Run a query to generate a RunTime column, making it look like this...

+-------------------------+--------------+
| procName | TimeEnded    |      RunTime |
+-------------------------+--------------+
|        A | 04:00:00.000 |         NULL |
|        B | 04:01:00.000 | 00:01:00.000 |
|        C | 04:03:00.000 | 00:02:00.000 |
|        A | 04:06:00.000 | 00:03:00.000 |
|        B | 04:10:00.000 | 00:04:00.000 |
|      ... |          ... |          ... |

and want to average the RunTime column for each distinct entry in the procName column, for something like this:

+-------------------------+
| procName |   AvgRunTime |
+-------------------------+
|        A | 00:03:00.000 |
|        B | 00:02:30.000 |
|        C | 00:02:00.000 |
|      ... |          ... |

How would I go about doing this? You can ignore the table1->table2 step, I just included it for some background information to describe my problem.

Basically how can I average the data in the RunTime column, based on distinct entries in the procName column?

Thanks.

A: 

Does the following work for you?

SELECT procName, AVG(RunTime)
FROM table
GROUP BY procName 

AVG will ignore your NULL entry however.

Chris Diver
It does, however the table it would be selecting from is dynamically generated based on the TimeEnded values from the first table -- it's not "free standing" in a sense. Would it be ineffecient if I ran the above query on the query to generate my procName/RunTime table?
gjk