MySQL存储函数与php

MySQL存储函数与php,php,mysql,function,Php,Mysql,Function,所以我有这个查询来获取所有帖子 select id, title from posts where type = 'article' 我有一个存储函数,可以计算视图总数并返回结果 我知道我可以像这样执行它 select totalView(id) 但是,如何合并这两个查询以返回包含每个帖子的总视图的所有帖子呢 也许像 select id, title, totalView(id) as total from posts where type = 'article' 多谢各位 sel

所以我有这个查询来获取所有帖子

select id, title 
from posts 
where type = 'article'
我有一个存储函数,可以计算视图总数并返回结果

我知道我可以像这样执行它

select totalView(id)
但是,如何合并这两个查询以返回包含每个帖子的总视图的所有帖子呢

也许像

select id, title, totalView(id) as total 
from posts 
where type = 'article'
多谢各位

select count(*) as total, id, title from posts where type = 'article'
编辑:它将统计$id的所有行

select count(*) as total, id, title from posts where type = 'article' AND id = $id;

感谢您的评论,但totalView是一个存储函数,它以帖子id为参数并返回总视图。请显示totalView函数您给出的示例是对您所问问题的回答。