我正在搞乱一些统计工具。我的数据库看起来像这样:
ip | campaign_id | authorized | stamp
-----------------------------------------------------
182.74.723.1 | 1 | 0 | 12349210211
82.14.127.1 | 3 | 1 | 29834043899
我想说一句话:
广告系列上有“XXX”点击,ID为“X”(“XXX”已获得授权,“XXX”未获得授权)
到目前为止我的代码:
$query = "SELECT campaign_id, COUNT(ip) FROM stats GROUP BY campaign_id";
$result = mysql_query($query) or die(mysql_error());
// Print out result
while($row = mysql_fetch_array($result)) {
echo "There are <b>". $row['COUNT(ip)'] ." hits</b> on campaign with <b>ID ". $row['campaign_id'] ."</b> (HERE COMES THE PART I'M LOOKING FOR)";
echo "<br />";
}
现在问题:我找不到计算“auth”的不同值的解决方案。 如果有人能帮我解决这个问题,我会很高兴,提前谢谢!
答案 0 :(得分:2)
试试这个SQL查询:
SELECT campaign_id,
COUNT(ip) as tot,
sum(authorized=0) as a0,
sum(authorized=1) as a1,
....
FROM stats GROUP BY campaign_id