Average Time On Shelter By Size and Species
###
Statistics
###
33018/PostgreSQL rev04
###
Average time spent on shelter for all animals by size and species for a date range.
###
en
###
SELECT
species.SpeciesName,
lksize.Size,
CAST(AVG(DaysOnShelter) AS INTEGER) AS avtimeonshelter
FROM animal
INNER JOIN lksize ON lksize.ID = animal.Size
INNER JOIN species ON species.ID = animal.SpeciesID
WHERE DaysOnShelter > 0 
AND NonShelterAnimal = 0 AND HasPermanentFoster = 0
AND DateBroughtIn > '$ASK DATE Enter the from date$' AND DateBroughtIn < '$ASK DATE Enter the to date$'
GROUP BY species.SpeciesName, lksize.Size
ORDER BY avtimeonshelter DESC
###
$$HEADER
<table border="1">
<thead>
<tr>
<th>Species</th>
<th>Size</th>
<th>Average Days On Shelter</th>
</tr>
</thead>
<tbody>
HEADER$$

$$BODY
<tr>
<td>$SPECIESNAME</td>
<td>$SIZE</td>
<td>$AVTIMEONSHELTER</td>
</tr>
BODY$$

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

