这是我的SQL查询
$sql = "SELECT *, COUNT(seen)
FROM usr_details
WHERE seen=0 AND UserID=3
GROUP BY UserID";
$unread = mysqli_query($DB, $sql);
$NumberUnread = mysqli_num_rows ($unread);
echo $NumberUnread;
这是小提琴
http://sqlfiddle.com/#!9/bc3f08/20/0
输出1 1而不是输出 2 我该如何解决这个问题?
答案 0 :(得分:0)
我猜您的问题出在GROUP BY
当您使用Group时,您需要明确该字段。
SELECT det_id,usr_id,COUNT(seen)
FROM user_details
WHERE seen=0 AND usr_id=3
GROUP BY det_id,usr_id