MySQL存储函数和php

时间:2015-01-03 17:11:38

标签: 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'

谢谢。

1 个答案:

答案 0 :(得分:0)

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;