SQL Count给出1 1而不是2

时间:2018-03-26 05:33:08

标签: mysql sql

这是我的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 我该如何解决这个问题?

1 个答案:

答案 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