How would I get a count of emails for each Day?
The monitoring volume has a structure of:
<Root>
----Year (subtype=751)
--------Month (subtype=751)
------------Day (subtype=751)
----------------Hour (subtype=751)
--------------------<buckets 1-n> (subtype=751)
------------------------Emails (subtype=749)
I can get a count down to the hour level, but am getting stuck there.
Here is what I have so far:
SELECT d1.DATAID, d1.parentid, d1.NAME, count(d2.dataid) Children FROM DTreeCore d1
join DtreeCore d2 on (d1.dataid = d2.parentid) and d1.subtype in (751,749)
and d1.parentid = %1
group by d1.dataid,d1.parentid,d1.name
union
SELECT d1.DATAID, d1.parentid, d1.NAME, count(d2.dataid) Children FROM DTreeCore d1
join DtreeCore d2 on (d1.dataid = d2.parentid) and d1.subtype in (751,749)
and d1.dataid = %1
group by d1.dataid,d1.parentid,d1.name
union
SELECT d1.DATAID, d1.parentid, d1.NAME, count(d2.dataid) FROM DTreeCore d1
join DtreeCore d2 on (d1.dataid = d2.parentid) and d1.subtype in (751,749)
and d1.dataid in
(select dataid from dtreecore where parentid in
(select dataid from dtreecore where parentid = %1) and subtype in (751,749))
group by d1.dataid,d1.parentid,d1.name
%1 = the DataID of the Year level
Results look similar to:
DATAID parentid NAME Children
1137450 1119878 2016 2
1137451 1137450 11 1
1182522 1137451 30 13
1195621 1137450 12 31
1195622 1195621 1 24
So I can see that:
There are 2 Month folders in 2016
There is 1 Day folder in 11
There are 13 Hour folders in 30
If I was to do it manually, say for 30-11-2016 as an example, I would just use:
SELECT COUNT(*) FROM DTree
WHERE DataID IN (SELECT DataID FROM DTreeAncestors where AncestorID=1182522)
AND SubType = 749
But how would I do it for all days in 2016? Am I even on the right track here?