所以我有这个查询来获取所有帖子
select id, title
from posts
where type = 'article'
我有一个存储函数来计算视图总数并返回结果
我知道我可以像
那样执行它select totalView(id)
但是如何合并两个查询以返回所有帖子以及每个帖子的总视图
可能像
select id, title, totalView(id) as total
from posts
where type = 'article'
谢谢。
答案 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;