SELECT numTimesIndexLoaded, numTimesIndexLoadedUnique, numTimesResultsLoaded, numTimesResultsLoadedUnique, numTimesCTALoaded, numTimesCTALoadedUnique
FROM
(SELECT
sum(ctaSL.page = 'index') AS numTimesIndexLoaded,
sum(ctaSL.page = 'results') AS numTimesResultsLoaded,
sum(ctaSL.page = 'cta') AS numTimesCTALoaded,
count(distinct ctaSL.ip_address, ctaSL.page = 'index') AS numTimesIndexLoadedUnique,
count(distinct ctaSL.ip_address, ctaSL.page = 'results') AS numTimesResultsLoadedUnique,
count(distinct ctaSL.ip_address, ctaSL.page = 'cta') AS numTimesCTALoadedUnique
FROM
stats_page_loads AS ctaSL
WHERE ctaSL.campaign_id = ?
AND ctaSL.mode = ?
) t1
I have the following prepared statement where I'm trying to get stats for a web page. The goal is to have both the stats of how many times each of the three pages is load, but also how many times it's loaded by a unique IP address for each of the three pages. I'm new to using distinct, so not even sure if it's the right thing to use, but I'm not getting the proper result so I'm assuming I'm using it wrong.
I figured I could just make another SELECT statement as t2, but trying to avoid that since I'll have to add the ? variables over and over again the more I add to it, so was hoping to have it condensed into one, if possible.