计数的平均值

时间:2011-09-20 18:47:15

标签: sql-server sql-server-2005 tsql sql-server-2008

我有一个名为totals的表,数据如下:

ACC_ID  Data_ID  Mon      Weeks   Total_AR_Count   Total_FR_Count  Total_OP_Count
23      9        01/2011  4       172              251             194
42      9        01/2011  4       2                16              28
75      9        01/2011  4       33               316             346
75      9        07/2011  5       1                12              20
42      9        09/2011  5       25               758             25

我希望输出为按ACC_ID和Data_ID分组的所有计数的平均值:

ACC_ID   Data_ID  Avg_AR_Count  Avg_FR_Count  Avg_OP_Count
23       9        172           251           194
42       9        13.5          387           26.5
75       9        17            164           183

怎么做呢?

1 个答案:

答案 0 :(得分:3)

您对所需内容的描述会编写SQL:

SELECT ACC_ID, Data ID, AVG(Total_AR_Count) AS Avg_AR_Count, AVG(Total_FR_Count) AS Avg_FR_Count...
  FROM table
 GROUP BY ACC_ID, Data_ID