我有这个查询:
select
problem_comments.user_id ,
problem_comment_id ,
problem_id ,
first_name ,
count(problem_comment_id) num
from problem_comments
left join users on problem_comments.user_id = users.user_id
where problem_id = 222
group by problem_comments.comment
它是列出问题的表和列出该问题的评论的另一个表的基本联接。
我试图用 count(problem_comment_id)
做的是查看问题中有多少条评论,以便我可以显示该计数。当前查询的问题是它返回 3 行,因为这个问题有 3 个注释。但在“num”列中它始终列出 1。
我如何才能不断获取相同的问题和评论数据,同时还能获取评论总数?
谢谢!!
最佳答案
我看到 php标记,因此...您可以在执行查询后使用 num_rows
函数。
Here is some information if you are using mysqli
.
如果您正在使用 mysql
扩展(如果是的话,那真是太遗憾了!),you can use mysql_num_rows()
关于mysql - 如何在同一查询中获取返回行数和数据的 count(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8565709/