-2
我正在计算名为ptb_profile_views
的mysql表中的行数。如果列数据重复,mysql不会重复计数两次
我的表看起来像这样:
id | profile_id | viewed_profile_id | date_time |
1 1 6
2 2 6
3 2 6
4 2 6
5 3 6
此刻我的查询计算表中的所有行。但是,我只希望它对不包含重复值的行在profile_id
中进行计数。
因此,如果用户2/profile_id 2多次查看用户6的配置文件,在这种情况下他们这样做,我只希望查询计算一次。我试图使用不同的,但它不工作。有人可以告诉我我要去哪里吗?
function check_profile_views() {
global $connection;
global $_SESSION;
$query = "SELECT DISTINCT COUNT(id) FROM ptb_profile_views WHERE viewed_profile_id=".$_SESSION['user_id']." AND profile_id='0'";
$check_profile_views_set = mysql_query($query, $connection);
confirm_query($check_profile_views_set);
return $check_profile_views_set;
}
重复http://stackoverflow.com/questions/15870709/mysql-do-not-count-duplicate-rows – Amir 2013-04-08 03:26:23