select
floor(deweyClass) as dewey,
month(checkOut) as month,
sum(timestampdiff(day, date(checkOut), date(checkIn))) as totaltime,
sum(1) as totalnum
from
spl3._rawXmlDataCheckIns
where
_rawXmlDataCheckIns.deweyClass >= 100 and
_rawXmlDataCheckIns.deweyClass < 200
and (checkOut is not null and checkIn is not null
and timestampdiff(day, date(checkOut), date(checkIn)) >= 1
and timestampdiff(day, date(checkOut), date(checkIn)) <= 100)
and (year(checkOut) >= 2013 and year(checkOut) < 2014)
group by
floor(deweyClass),
month(checkOut);