sql server 2005 聚合函数计算(2)

4.  计算累加

                     使用子查询来计算累加和

                     使用子查询来获得一个结果集中的所有。

                                       select orderdate

                                                    SUM(totalDue) as sales

                                                                 (select SUM(totalDue)

                                                                  from sales.slesorderheader

                                                                   where(orderdate <= A.arderdate)

                                                                  )  AS [actual sales]

                                      from sales.salesorderheader as A

                                      group by orderdate

                                       order by orderdate

 

5.计算统计值

             使用AVG求平均值

             使用MIN 和MAX求最小值和最大值

所有的聚合函数都可以接受DISTINCT修饰符,这会使聚合计算只在惟一的值上执行。

相关文章
相关标签/搜索