统计SQL表中的数据

发布于 2025-01-01 02:45:26 字数 1079 浏览 0 评论 0原文

我的查询:

           "SELECT id
            FROM user_follow
            WHERE user_id IN(3,6) AND follow_id NOT IN(3,6)
            GROUP BY follow_id";

它显示:

[users] => Array
    (
        [0] => Array
            (
                [id] => 20
            )

        [1] => Array
            (
                [id] => 9
            )

        [2] => Array
            (
                [id] => 19
            )

    )

我需要计算数据(在本示例中查询必须返回 3 作为结果)


我尝试了 COUNT(id) 但结果对我来说不好。

结果:

        [0] => Array
            (
                [count(id)] => 1
            )

我尝试了 SELECT count(1)

结果:

        [0] => Array
            (
                [count(1)] => 1
            )

        [1] => Array
            (
                [count(1)] => 2
            )

        [2] => Array
            (
                [count(1)] => 1
            )

仍然不是一个数字 (3)。我想要这样的东西 [users] => 3

my query:

           "SELECT id
            FROM user_follow
            WHERE user_id IN(3,6) AND follow_id NOT IN(3,6)
            GROUP BY follow_id";

and it show :

[users] => Array
    (
        [0] => Array
            (
                [id] => 20
            )

        [1] => Array
            (
                [id] => 9
            )

        [2] => Array
            (
                [id] => 19
            )

    )

I need to count data (in this example query must give back 3 as result)


I tried COUNT(id) but result was not good for me.

result :

        [0] => Array
            (
                [count(id)] => 1
            )

I tried SELECT count(1)

result :

        [0] => Array
            (
                [count(1)] => 1
            )

        [1] => Array
            (
                [count(1)] => 2
            )

        [2] => Array
            (
                [count(1)] => 1
            )

Still not not one number (3). I want something like this [users] => 3

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

北风几吹夏 2025-01-08 02:45:26

如果您只需要数字而不需要数据本身,您可以尝试以下操作:

SELECT count(1)
FROM user_follow
WHERE user_id IN(3,6) AND follow_id NOT IN(3,6)
GROUP BY follow_id

If you need only the number and not the data itself you can try this:

SELECT count(1)
FROM user_follow
WHERE user_id IN(3,6) AND follow_id NOT IN(3,6)
GROUP BY follow_id
暮色兮凉城 2025-01-08 02:45:26
$count=mysql_num_rows($sql);

你可以试试这个

$count=mysql_num_rows($sql);

you can try this

归属感 2025-01-08 02:45:26

如果我理解您的需求,您可以对数组本身使用 count ,如下所示:

                $count=count($users)

if I am understanding your need, you can use count on the array itself as follows :

                $count=count($users)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文