Is there a way of combing some additional sql into this query.
Each of the ‘guides’ can attend multiple sessions on a particular day. I want to count the number of unique days (which the query does not do), and also the total number of sessions for each guide overall, which the query below does do.
SELECT
Count(sessions.Event_Date),
sessions_link.Guide_Name,
guide_details.Gift_Aid,
guide_details.Post_Code
FROM
guide_details
INNER JOIN sessions_link ON sessions_link.ID_Guide = guide_details.ID_Guide
INNER JOIN sessions ON sessions_link.Session_ID = sessions.ID_Event
WHERE
guide_details.Gift_Aid = '1' AND
sessions.Event_Date BETWEEN '2014-01-01' AND '2014-12-31'
GROUP BY
sessions_link.Guide_Name,
guide_details.Gift_Aid,
guide_details.Post_Code
This give me for example
31 Ceri 1 BS9
42 David 1 BS32
34 Mary 1 BS16
Another query ‘splits up’ the sessions, but for example I want the answer ‘17’ for the number of days as ‘Ceri’ did 17 unique days, on 14 days she did a second session.
SELECT
guide_details.Gift_Aid,
Count(sessions.Event_Date),
sessions_link.Guide_Name,
guide_details.Post_Code,
sessions.Event_Session
FROM
guide_details
INNER JOIN sessions_link ON sessions_link.ID_Guide = guide_details.ID_Guide
INNER JOIN sessions ON sessions_link.Session_ID = sessions.ID_Event
WHERE
guide_details.Gift_Aid = '1' AND
sessions.Event_Date BETWEEN '2014-01-01' AND '2014-12-31'
GROUP BY
sessions_link.Guide_Name,
guide_details.Gift_Aid,
guide_details.Post_Code,
sessions.Event_Session
This gives me
1 17 Ceri BS9 10
1 14 Ceri BS9 13
1 21 David BS16 10
1 21 David BS16 13
1 18 Mary BS32 10
1 16 Mary BS32 13
From the above I would require for example;
1 17 Ceri BS9
1 21 David BS9
1 18 Mary BS32
Any pointers in the right direction in combining (if possible) the queries would be helpful.
Thanks in advance.