PHP MYSQL SQL 去掉重複的資料統計方法[特定時間內的人數統計]
PHP MYSQL SQL 去掉重複的資料統計方法[特定時間內的人數統計]
<?php
header(‘content-type:text/html;charset=utf-8’);
include(‘conn.php’);
if(isset($_POST[‘years’]))
{
$years=$_POST[‘years’];
$months=$_POST[‘months’];
$days=$_POST[‘days’];
$hours=$_POST[‘hours’];
$minutes=$_POST[‘minutes’];
$sql =”SELECT COUNT(DISTINCT value) FROM `all_data` WHERE value LIKE ‘%P_N%’ AND years=’$years’ AND months=’$months’ AND days=’$days’ AND hours=’$hours’ AND minutes=’$minutes'”;
//echo $sql;
$sql_data_count=mysql_query($sql); //改成自己的sql語法
$row = mysql_fetch_array($sql_data_count);
$counts=$row[0];
echo $years.’/’.$months.’/’.$days.’/’.$hours.’/’.$minutes.’,’.$counts;
}
?>