UNIQUE Recipient Counts - when Grouped by "Something" - Using QueryDef
Hi There,
I have a requirement whereby I would like to use the queryDef JS to query a custom "answer log" schema, and then get unique counts of recipients grouped by "answer".
Example data
Schema: dev: poll_trackingLogs
Recipient ID (@recipient-id) Answer (@answer) LogDate(@logDate)
1,818,610 A 04/04/2018 12:00:00
1,818,610 B 04/04/2018 16:23:49
1,818,611 D 04/04/2018 16:46:26
1,818,611 D 04/04/2018 16:49:02
1,818,611 B 04/04/2018 16:49:42
1,818,610 B 04/04/2018 16:52:40
1,818,610 C 04/04/2018 16:52:48
1,818,640 C 04/04/2018 17:01:49
1,818,611 C 04/04/2018 17:03:16
1,818,610 C 04/04/2018 17:03:50
I've been using the generic query editor (as this will help be generate the XML that i will then use in a JS queryDef statement within a webApp).
I have been able to obtain unique counts per recipient per answer (by using Countdistinct() expression and grouping by @answer, as below).
But what I'd really like to be able to do, is get unique counts per recipient (whereby their first log is then counted against the answer, but subsequent logs are not counted).
I would expect the output of the above data to look like this:
Answer Count
A 1
B 0
C 1
D 1
This is my approach to getting per recipient per answer (but as mentioned, this is not quite what I need)






In turn, my QueryDef for this approach is this:
<%
var query = xtk.queryDef.create(
<queryDef
schema="dev:poll_trackingLogs" operation="select">
<select>
<node expr="@answer" groupBy="1" />
<node alias="@count" expr="Countdistinct([@recipient-id])"
/>
</select>
<where>
<condition expr="@name = 'Tottenham''" />
</where>
<orderBy>
<node expr="@answer" sortDesc="false"/>
</orderBy>
</queryDef>
);
var result = query.ExecuteQuery();
%>