我有这些 sql 查询(我使用 codeigniter db 类):
$query = $this->db->select("a.title AS articles_title,
a.content AS articles_content,
a.excerpt AS articles_excerpt,
a.slug AS articles_slug,
a.views AS articles_views,
a.views AS articles_views,
CONCAT(up.first_name, ' ', up.last_name) AS articles_author,
DATE_FORMAT(a.created, '%T %d.%m.%Y') AS articles_created,
(SELECT IF(ROUND(AVG(av.vote),1), ROUND(AVG(av.vote),1), 0) FROM articles_votes av WHERE a.id = av.article_id) AS articles_votes,
(SELECT COUNT(ac.id) FROM articles_comments ac WHERE a.id = ac.article_id) AS articles_totalcomments", FALSE)
->from('articles a')
->join('user_profiles up', 'a.author_id = up.user_id')
->where('page_id', $page_id)
->order_by("a.$ordering")
->get();
对服务器资源和速度有好处吗?或者我应该创建另一个计算投票和评论的函数,它将计算所有评论和平均投票,然后将其添加到文章数组中?
谢谢