我有一个表(url_log
),其中包含一列(referer
)网址。有些网址是独一无二的,有些网址是重复的。使用PHP我想显示每个不同的URL(不重复)以及url在列中出现的次数。
这是我提出的,但这绝对是错误的:
echo '<table>';
$ref=$icdb->get_row("SELECT COUNT(referer) AS frequency, referer FROM url_log WHERE u = '".$dom."' GROUP BY referer ORDER BY frequency DESC");
foreach ($ref as $details) {
echo "<tr><td>".$details['referer']."</td><td>".$details['frequency']."</td></tr>";
}
echo '</table>';
任何提示?
答案 0 :(得分:2)
如果我理解你的问题,就应该这样做。
SELECT DISTINCT(referer), COUNT(referer) AS frequency
FROM url_log
GROUP BY referer
ORDER BY frequency DESC;
答案 1 :(得分:1)
用于选择列的每个不同值使用此查询
SELECT DISTINCT(column) AS columnname_key FROM table ;
计算重复使用此代码
SELECT Count(*) duplicatetable
FROM
(
select columname_to_check_dulicate_values, Count(*)
from tablename
group by name
having Count(*) > 1
) x