0
我需要在sql中生成分層摘要。在sql中的動態分組和僱主結果
用戶將發送的列組由作爲參數存儲的過程,所以按是動態
For eg. User will send to group records by DeptNo and then by Job columns
我需要產生的結果如下面 Final output
用於各個查詢通過DEPTNO
Select d.DEPTNO,Count(EmpNo) EmpCount, Sum(Sal) Total from Emp e inner join Dept d
on e.DEPTNO=d.DEPTNO GROUP BY d.DEPTNO;
由DEPTNO組查詢組,工作
select Deptno, Job, Count(EmpNo) EmpCount, Sum(Sal) Total from emp group by DEPTNO,Job order by deptno
目前我用來產生結果的查詢,如下
select Deptno, Job,
Count(EmpNo) EmpCount,
Sum(Sal) Total
from emp group by DEPTNO,Job with rollup order by Deptno, EmpCount desc
是否有其他更好的選擇,以獲得彙總結果。 這是顯示在mvc網站和沒有ssrs
我喜歡'with rollup'解決方案。它工作正常嗎? – vercelli
你應該避免'WITH ROLLUP'。它已被折舊並將從未來版本的SQL Server中刪除([Source](https://msdn.microsoft.com/en-us/library/ms177673.aspx))。而是使用[GROUPING SETS](https://technet.microsoft.com/en-us/library/bb510427(v = sql.105).aspx)。 –
@ destination-data:哇,不知道。謝謝。 – vercelli