Below is the SQL to a query that combines "Sum", "Group By" and "Count". In the case below, the field "ad group" is supposed to be counted and appear in a new field called "CountOfadGroup Id". The value it returns 170 and that is incorrect. It should be 14. When I switch the "count" to "group by", the query returns a list of the 14 rows I expected. How come I can't get the "count" to work?
Also, if you can offer any advice or links so I can learn to get queries like this to work in the future, I would really appreciate it. Specifically, I'm talking about queries that use "group-by", calculations and involve joins.
Thanks
Adam
Also, if you can offer any advice or links so I can learn to get queries like this to work in the future, I would really appreciate it. Specifically, I'm talking about queries that use "group-by", calculations and involve joins.
Thanks
Adam
Code:
SELECT adGroupHistoryMain.blastId, M_mainBlast.blastName, Sum(adGroupHistoryMain.clicks) AS SumOfclicks, Sum(adGroupHistoryMain.impression) AS SumOfimpression, Format((Sum([clicks])/Sum([impression])),"0.00%") AS CTR, Sum(adGroupHistoryMain.cost) AS SumOfcost, Count(adGroupHistoryMain.adGroupId) AS CountOfadGroupId, M_mainBlast.Created, DateDiff("d",[Created],Now()) AS Days, Sum([cost])/DateDiff("d",[Created],Now()) AS CPD
FROM adGroupHistoryMain INNER JOIN M_mainBlast ON adGroupHistoryMain.blastId = M_mainBlast.blastId
WHERE (((M_mainBlast.blastStatusId)=2) AND ((M_mainBlast.constructStatusId)=3))
GROUP BY adGroupHistoryMain.blastId, M_mainBlast.blastName, M_mainBlast.Created, DateDiff("d",[Created],Now());
Comment