MySQL中,distinct()和count(*)混合使用问题

统计大量非重复数据时,distinct和count混合使用。

SQL语句:

SELECT count( DISTINCT member_id ) FROM pt_member_enter WHERE ( ( add_time BETWEEN '".$date."' AND '".time()."' ) ) AND ( enter_num >= '1' );

在PHP中结合框架使用时:

$enter = Model()->query("SELECT count( DISTINCT member_id ) FROM >pt_member_enter WHERE ( ( add_time BETWEEN '".$date."' AND '".time()."' ) ) AND >( enter_num >= '1' )");
$freshness = $enter[0]['count( DISTINCT member_id )'];

返回的数据结构:

array(1) {
 [0]=>
 array(1) {
   ["count( DISTINCT member_id )"]=>
   string(4) "9652"
 }
}

你可能感兴趣的:(MySQl,PHP)