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

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;

关于php - MySQL存储函数和PHP,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27757359/

10-12 00:06
查看更多