我的代码:
$q = mysql_query("
SELECT
ads.title_ad AS title_ad,
COUNT(adclicks.ad_id) AS counted,
ads.dclicks AS dclicks
FROM ads
LEFT JOIN adclicks
ON ads.id = adclicks.ad_id GROUP BY ads.id
");
while($row = mysql_fetch_array($q))
{
if($row['counted'] > $row['dclicks'])
{
}
else
{
echo ''.$row['title_ad'].' '.$row['counted'].' '.$row['dclicks'].'<br>';
}
}
我只想删除if(){}
并想在sql查询中调整它。
解决方案是什么?怎么做?
答案 0 :(得分:0)
在SQL中添加HAVING子句:
HAVING COUNT(adclicks.ad_id) < ads.dclicks