本文介绍了如何获取结果集最后一行中所有列值的总和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 嗨我正在使用GridView,它显示以下查询中的值,我需要在页脚的每一行获得总计 这样的东西: R1 AB R2 5 6 R3 1 11 tot 6 17 b $ b 我尝试过:Hi I am Working on a GridView which Displays the values from the below query,and I need to get the Total of each row at its footersomething like this:R1 A BR2 5 6R3 1 11tot 6 17What I have tried:;with t1 as (SELECT DeptID, COUNT(EmpID) AS TotalHeadCount FROM EmployeeDetailsWHERE (datepart(yyyy,DOJ) between 2005 and @years) and Status =0group by DeptID),t2 as (SELECT DeptID,COUNT(EmpID) AS NewJoinees FROM EmployeeDetails AS EmployeeDetails_7WHERE (DATEPART(yyyy, DOJ) = @years) AND (DATEPART(mm, DOJ) = @months) and datepart(mm,DOJ)>= @months and Status = 0group by DeptID),t3 as (SELECT DeptID,COUNT(EmpID) AS Resigned FROM EmployeeDetails AS EmployeeDetails_7WHERE (DATEPART(yyyy, deactivate) = @years) AND (DATEPART(mm, deactivate) = @months) and datepart(mm,deactivate)>= @months and Status =1 group by DeptID),t4 as (Select Distinct DeptID,Tobehired As ToBeHired,Openposition As OpenPositions,Status As Status1 From RecruitmentDetails1WHERE Tobehired=45)Select t1.DeptID, CASE WHEN TotalHeadCount IS NULL THEN '0' ELSE TotalHeadCount END AS TotalHeadCount,CASE WHEN NewJoinees IS NULL THEN '0' ELSE NewJoinees END AS NewJoinees,CASE WHEN Resigned IS NULL THEN '0' ELSE Resigned END AS Resigned, t4.Tobehired as ToBeHired, t4.OpenPositions as OpenPositions, t4.Status1 as Status1from t1 full outer join t2 on t1.DeptID = t2.DeptIDfull outer join t3 on t1.DeptID = t3.DeptIDfull outer join t4 on t1.DeptID = t4.DeptID推荐答案其中一个 Codeproject搜索结果 []应该是你的目标One of these Codeproject Search results[^] should be what you are after 这篇关于如何获取结果集最后一行中所有列值的总和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-13 17:20