sqlserver中简单统计查询

时间:2021-09-14 04:35:26

     也许大家在做报表的时候通常会碰到后面要加合计一行。经过一翻研究发现sqlserver里面有比较好的提示

        //  例

          表名称  Staff

          ID          UserName    Salary

          1                 张三           3000

          2                 李四           5000

          3                 王武           6000

          4                 赵六           5000

 

 

         最后老板想统计每个月需发放工资

        SELECT UserName,SUM(Salary) From Staff Group BY UserName with culb

 

        查询结果  

                           张三           3000

                           李四           5000

                           王武           6000

                           赵六           5000

                           NULL         16000