我正在尝试找出表中不同的clientId的总数
这是查询
$stmt = $conn->prepare("SELECT DISTINCT count(clientId) as totalrecords FROM quotes WHERE storeEmail = '". $store['email']. "'");
$stmt->execute();
$totalRecords = $stmt->fetch(PDO::FETCH_COLUMN);
echo 'Total Users Found with Request Quote : ' . $totalRecords . "<br /><br />";
echo 'Press Send button to send notifications to all users <br /><br />';
$query = "SELECT DISTINCT clientId FROM quotes WHERE storeEmail = '". $store['email']. "'";
$stmt = $conn->prepare($query);
$stmt->execute();
$clients = $stmt->fetchAll(PDO::FETCH_COLUMN);
第一个查询给了我147,而第二个查询给了我60
第一个查询出了什么问题。
COUNT DISTINCT
您要寻找的是:
$query = "SELECT COUNT(DISTINCT clientId) FROM quotes WHERE storeEmail = '". $store['email']. "'";
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句