我有一个这样的查询:
select display_order , section_name , solution_section_id from solution_sections order by display_order
它非常基础,可以获取特定讨论的部分。有用。
我想要做的是还显示每个部分中的评论数量。所以我想在评论表上做一个连接,并计算有多少评论。
这是其他表的架构:
mysql> describe suggested_solution_comments;
+-----------------------+----------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------+----------------+------+-----+---------+----------------+
| comment_id | int(10) | NO | PRI | NULL | auto_increment |
| problem_id | int(10) | NO | | NULL | |
| suggested_solution_id | int(10) | NO | | NULL | |
| commenter_id | int(10) | NO | | NULL | |
| comment | varchar(10000) | YES | | NULL | |
| solution_part | int(3) | NO | | NULL | |
| date | date | NO | | NULL | |
| guid | varchar(50) | YES | UNI | NULL | |
+-----------------------+----------------+------+-----+---------+----------------+
8 rows in set (0.00 sec)
mysql> describe solution_sections;
+---------------------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+---------------+------+-----+---------+----------------+
| solution_section_id | int(10) | NO | PRI | NULL | auto_increment |
| display_order | int(10) | NO | | NULL | |
| section_name | varchar(1000) | YES | | NULL | |
+---------------------+---------------+------+-----+---------+----------------+
所以它必须是 solution_section_id 和 solution_part 的连接(即使它们的命名有些不一致,它们也是外键)其中问题 ID = 一些 ID。
但是,我将如何获得Suggested_solution_comments 表中返回评论的数量?
谢谢!