统计SQL表中的数据
我的查询:
"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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您只需要数字而不需要数据本身,您可以尝试以下操作:
If you need only the number and not the data itself you can try this:
你可以试试这个
you can try this
如果我理解您的需求,您可以对数组本身使用 count ,如下所示:
if I am understanding your need, you can use count on the array itself as follows :