I am currently running a query that looks like this:
SELECT campaigns.id, lead_stats.camp_id, lead_stats.country, campaigns.name, SUM(lead_stats.leads) AS lead, SUM(lead_stats.clicks) AS click,TRUNCATE(100.0 * SUM(lead_stats.leads) / SUM(lead_stats.clicks), 1) AS conv_rate
FROM lead_stats
JOIN campaigns
ON campaigns.id = lead_stats.camp_id
WHERE lead_stats.date > DATE_SUB(NOW(), INTERVAL 24 HOUR)
AND lead_stats.from_product = 4
AND lead_stats.camp_id NOT IN (
SELECT camp_id
FROM suspicious_offer_clears
WHERE clear_until > '".date('Y-m-d H:i:s')."'
AND alert_type = 3
)
GROUP BY lead_stats.camp_id
HAVING (SUM(lead_stats.leads) / SUM(lead_stats.clicks)) < 0.1
ORDER BY lead_stats.camp_id
It gets some information that is not important really for my question that I have. However, I was curious on how I could, in this SQL statement, do an if statement on the lead_stats.country. I want to see if the country is NOT equal to "US", and if it is NOT equal to "US" I want to see if the SUM(lead_stats.click) for that row is greater than 20. I decided I would try to do it in my php template because I could not figure out how to do on MySQL.
Here is what I have on my template for that.
<?php
while ( $row = mysql_fetch_assoc($getConresult) ) {
if($row['country'] != "US"){
if($row['click'] > 19){
//not sure what to do here because it is less than 20, so I do not want to include this in my output on the table
}
}
So I am wondering how I can skip a record if it does not match my criteria stated above. I was thinking I could use a for statement but had some confusion on that front. Any help would be appreciated!