troubleshooting Question

sqlite get last time based on message value

Avatar of Afif JABADO
Afif JABADO asked on
MySQL ServerGolangSQL
11 Comments2 Solutions60 ViewsLast Modified:
SELECT groups.id, groups.name, groups.modified_date, 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',  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(events.time) as time,events.campaign_id, targets.id, targets.email, targets.first_name, targets.last_name, targets.position from groups left join group_targets 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 targets.email

i want to get the last time when events.message = 'Submitted Data'
as well the last time when events.message = 'Reported '

gophish.db

I am using sqlite .db i have attached

// GetTargets performs a many-to-many select to get all the Targets for a Group
func GetAllTarget() ([GTarget, error) {
      ts := [GTarget{}
      err := db.Table("groups").Joins("left join group_targets gt ON groups.id = gt.group_id").Joins("left join targets ON targets.id = gt.target_id").Joins("left JOIN events on events.email = targets.email").Group("events.campaign_id,events.email").Select("groups.id, groups.name, groups.modified_date, 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',  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(events.time) as time,events.campaign_id, targets.id, targets.email, targets.first_name, targets.last_name, targets.position").Group("targets.email").Order("submitted_data desc").Limit(10).Scan(&ts).Error
      return ts, err
}
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 11 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros