ASKER
ASKER
ASKER
id | name | email_sent | email_opened | clicked_link | submitted_data | LastSubmittedDatatime | LastReportedEmailtime | campaign_id | id | first_name | last_name | position | |||
1 | cyberx Users | 1 | 0 | 0 | 0 | 7 | 4 | awareness@cyberx-sa.com | |||||||
1 | cyberx Users | 5 | 5 | 4 | 4 | 2020-05-06 12:42:14.6425167+00:00 | 7 | 1 | panda@cyberx-awareness.com | panda | cyberx | Systems Administrator | |||
1 | cyberx Users | 7 | 0 | 0 | 0 | 7 | 2 | stc@cyberx-awareness.com | stc | cyberx | Systems Administrator | ||||
1 | cyberx Users | 7 | 0 | 0 | 0 | 7 | 3 | test@cyberx-awareness.com | test | cyberx | Systems Administrator | ||||
ASKER
select
[groups].[id]
, [groups].[name]
, sum(case when [events].[message] = 'Email Sent' then 1 else 0 end) as 'email_sent'
, sum(case when [events].[message] = 'Email Opened' then 1 else 0 end) as 'email_opened'
, sign(sum(case when [events].[message] = 'Clicked Link' then 1 else 0 end)) as 'clicked_link'
, sum(case when [events].[message] = 'Submitted Data' then 1 else 0 end) as 'submitted_data'
, max(case when [events].[message] = 'Submitted Data' then [events].time else null end) as 'LastSubmittedDatatime'
, max(case when [events].[message] = 'Email Reported' then [events].time else null end) as 'LastReportedEmailtime'
from [groups]
left join [group_targets] as [gt] on [groups].[id] = [gt].[group_id]
left join [targets] on [targets].[id] = [gt].[target_id]
left join [events] on [events].[email] = [targets].[email]
group by [groups].[id], [groups].[name]
If you want to ask more then create a new question because it is already answered.
ASKER
SQL (Structured Query Language) is designed to be used in conjunction with relational database products as of a means of working with sets of data. SQL consists of data definition, data manipulation, and procedural elements. Its scope includes data insert, query, update and delete, schema creation and modification, and data access control.
TRUSTED BY
ASKER
mailto:xxx@xyz.com/1/Submitted Data
mailto:xxx@xyz.com/1/Submitted Data
mailto:xxx@xyz.com/2/Submited Data
I want the result will be like that
email/total Submitted Data
mailto:xxx@xyz.com/2
why is 2 ? because if there is duplicated of Submitted Data in the same campaign compute it as only 1 occurence if not found the total will be 0