sql - MySQL: Combine union and top 3 count of leads -
i'm trying obtain each campaign type , 3 lead names have (top 3) attendances each campaign type. should looks this:
+-------+-----------+ | code | leadname | +-------+-----------+ | wp | lead | | wp | lead b | | wp | lead c | | cf | lead b | | cf | lead c | | cf | lead | | tl | lead b | | tl | lead | | tl | lead c | campaign table: campaignid, campaignname, campaignstartdate, code campaign members table:campaignid, leadid, campaignmemberstatus, campaignmembersignupdate leads table: leadid, leadname, accountid
campaignid links campaign --> members, leadid links members --> leads i'm struggling on how union , provide top 3 leadnames.
select top 3 abc.code,abc.leadname ( select a.code,c.leadname,count(*) total campaign left join [campaign members] b on b.campaignid = a.campaignid left join leads c on c.leadid = b.leadid group a.code, c.leadname order count(*) ) abc
Comments
Post a Comment