Adrian Cross
asked on
SQL Pivot Table - SUM in two columns
Need to accumulate the totals, but at different places....
SELECT [1],[2],[3],[4],[5],[6],isnull([1],0)+isnull([2],0)+isnull([3],0)+isnull([4],0)+isnull([5],0)+isnull([6],0) as [TOTAL MARKS], [TOTAL EXTRA]
FROM
(SELECT mygroup, q, marks, sum(extra) as [TOTAL EXTRA]
FROM yourtable
GROUP BY mygroup,q,marks) src
PIVOT
(
SUM(marks) FOR q IN ([1],[2],[3],[4],[5],[6]) ) pvt
OOps, spotted a mistake, not grouping for the overall.
Back in a minute...
Back in a minute...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Superb answer Mark Wills.
Thanks
Thanks
A pleasure Adrian :)
Open in new window