Monthly days on shelter by species
###
Statistics
###
3123/PostgreSQL rev02
###
Total of all days spent on shelter for each species for a calendar month.
###
en
###
$VAR dt DATE Select which month/year to produce figures for$

SELECT D1+D2+D3+D4+D5+D6+D7+D8+D9+D10+D11+D12+D13+D14+D15+D16+D17+D18+D19+D20+D21+D22+D23+D24+D25+D26+D27+D28+D29+D30+D31 AS DaysOnShelter,
SpeciesName
FROM animalfigures
INNER JOIN species ON species.ID = animalfigures.SpeciesID 
WHERE Code = 'SP_ONSHELTER' AND 
Month = CAST(EXTRACT(MONTH FROM DATE('$@dt$')) AS INTEGER) AND
Year = CAST(EXTRACT(YEAR FROM DATE('$@dt$')) AS INTEGER) AND
D1+D2+D3+D4+D5+D6+D7+D8+D9+D10+D11+D12+D13+D14+D15+D16+D17+D18+D19+D20+D21+D22+D23+D24+D25+D26+D27+D28+D29+D30+D31 > 0
ORDER BY SpeciesName
###
$$HEADER
<table border="1">
<thead>
<tr>
<th>Species</th>
<th>Total Days On Shelter</th>
</tr>
</thead>
<tbody>
HEADER$$

$$BODY
<tr>
<td>$SPECIESNAME</td>
<td>$DAYSONSHELTER</td>
</tr>
BODY$$

$$FOOTER
</tbody>
</table>
FOOTER$$

