MySQL 存储函数和 php


MySQL Stored functions and php

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

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;