I have a function that tracks clicks. it groups them by day so the user only gets credit for one click per day.
The client wants it so on one special day the user gets credit for all clicks on that day.
My initial idea is to have two functions. the first function pulls all the clicks that do NOT equal the special date and group them by day. The second functions pulls only clicks from the special date. Then I add the two together.
Is there a way to write the query so I don’t have to use two functions?
my current query to pull all clicks that are NOT on the given date is:
$sql = "SELECT DATE(timeclicked) AS Date, platform, COUNT(DISTINCT email) AS click_sum
FROM trackclicks
WHERE email='".$email."'
AND uid='".$uid."'
AND action LIKE '%completed%'
AND date(timeclicked) != CAST('".$giving_date."' AS DATE)
GROUP BY platform, DATE(timeclicked) ";
ADDITION
this is in addition to my last question. The query worked and displays this in PHPMyAdmin
Date platform click_sum
2015-10-03 Facebook 13
2015-10-04 Facebook 1
2015-10-03 Twitter 14
2015-10-04 Twitter 1
my query ends with this:
if ($result = $mysqli->query($sql)) {
$response['sum'] = $result->num_rows;
}
which is giving me 2 and I need it to give me 14 for facebook and 15 for twitter
GROUP by platformat the end of the query. But this will screw up the counts. You can probably accomplish the funky logic of allowing non-distinct counts on that one specific date in a subquery, which will allow you to then group your results. It only worked when you were grouping by date and doing the conditional logic for a date, now that you want to group by platform and combine dates I don't think it will work that way, need a subquery.