是否可以将这 3 个查询放在一个 sql 查询中?
我已经研究过 JOIN,但无法弄清楚如何计算展示次数和点击次数 - 见下文
$date_where = " rec_use_date > '2013-04-16 17:05:00' AND rec_use_date < '2013-04-23 00:00:00' ";
$q = " SELECT * FROM tracking_table ";
$q .= " WHERE ".$date_where;
$o =0;
$result = mysql_query($q);
while ($db = mysql_fetch_assoc($result)) {
$rowKey = md5($db['rec_trk_id']);
$rows[$rowKey]['use_ip'] = $db['rec_use_ip'];
$rows[$rowKey]['ad_code'] = $db['rec_trk_id'];
$rows[$rowKey]['ad_location'] = $db['rec_tar_page'];
$q_impressions = mysql_query("SELECT COUNT(*) FROM tracking_table WHERE rec_trk_id = '{$db['rec_trk_id']}' AND rec_use_ip LIKE 'Ad loaded' AND ".$date_where) or die(mysql_error());
$db_impressions = mysql_fetch_assoc($q_impressions);
$rows[$rowKey]['impressions'] = $db_impressions['COUNT(*)'];
++$o;
$q_clicks = mysql_query("SELECT COUNT(*) FROM tracking_table WHERE rec_trk_id = '{$db['rec_trk_id']}' AND rec_use_ip NOT LIKE 'Ad loaded' AND ".$date_where) or die(mysql_error());
$db_clicks = mysql_fetch_assoc($q_clicks);
$rows[$rowKey]['clicks'] = $db_clicks['COUNT(*)'];
$rows[$rowKey]['conversion'] = round((($db_clicks['COUNT(*)']/$db_impressions['COUNT(*)'])*100),2);
++$o;
}