课程表,订单表(统计报名人数),评论表(统计评论的人数),点赞表(点赞人数)
利用sql是最精准的做法
SELECT
tc.id,
tc.title,
tc.img,
(SELECT COUNT(1) FROM t_shoporder WHERE course_id = tc.id) AS ordercount,
(SELECT COUNT(1) FROM t_course_comment WHERE course_id = tc.id) AS commentcount
FROM t_course tc
时间: 2024-10-05 23:09:09