统计相同的order_id并在SQL中输出有多少个
我想计算表 refnumbers
中有多少行具有相同的 order_id
因此它应该输出:
There's 5 rows with the order_id 123
There's 9 rows with the order_id 124
There's 18 rows with the order_id 125
There's 2 rows with the order_id 77
这是它应该在表中计数的列 order_is
< code>refnumbers
如果没有特别提到 order_id,然后在 php 中对它们进行循环,我真的不知道如何做到这一点。
I would like to count how many rows there is of the same order_id in the table refnumbers
So it should output:
There's 5 rows with the order_id 123
There's 9 rows with the order_id 124
There's 18 rows with the order_id 125
There's 2 rows with the order_id 77
It's the column order_is
that it should counter after in the table refnumbers
I dont really know how to do this without specifically mention a order_id and then do a loop through them in php.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在要获取其计数的列上使用
group by
。这不起作用
将为您提供包含所有行计数的单行
每个不同 order_id 的计数
将为您提供每个不同 order_id 的计数。
如果您想获取总计数,请取消注释
with rollup
部分。You need to use
group by
on the column that you want to get the count for.This does not work
Will give you a single row with all rowcounts
Count per distinct order_id
Will give you the count per distinct order_id.
If you want to get the total count as well uncomment the
with rollup
part.