I have a query:
<cfquery name="pivotquery">
SELECT employeedept,cse_name,YEAR,January,February,March,April,May,June,July,August,September,October,November,December
FROM (
SELECT month= datename(month,execoffice_date)
, YEAR =YEAR(execoffice_date)
, employeedept
, COUNT(*) as 'totalstars'
FROM CSEReduxResponses
WHERE execoffice_status = 1
GROUP BY employeedept
, month(execoffice_date)
, YEAR(execoffice_date)
, DATENAME(month,execoffice_date)
)
AS r
JOIN csedept d ON d.cse_dept = r.employeedept
PIVOT
(
SUM(totalStars)
FOR [month] IN (
[January],[February],[March],[April],
[May],[June],[July],[August],
[September],[October],[November],[December]
)
)
AS pvt
</cfquery>
This gets me all the data I want based on the month and year. I'm outputing the results in a table:
<table >
<thead>
<tr>
<th>Department</th>
<th>January</th>
<th>Frebruary</th>
.........
</tr>
</thead>
<tbody>
<cfoutput query="pivotquery" >
<tr>
<td>#pivotquery.csedept_name#</td>
<td>#pivotquery.January#</td>
<td>#pivotquery.February#</td>
.......
</tr>
</cfoutput>
</tbody>
</table>
Yes is outputting the data correctly. How can I get it to output the results in a separate table by year?
If you take a look at this sqlfiddle, it has 2014 and 2015 data. So I would like generate a separate table for each year. So with the data I created in the sqlfiddle, it would have 2 tables: one for 2014 and 2015.