场景:查询所有A表的数据,并且关联B表,再数据集中插入一个COUNT列。该列的数据是B表的COUNT
扩展:假设join的表数据为空,但我任然要把所有表A的数据取出来,那就用LEFT JOIN
SELECT * FROM question AS A JOIN (SELECT question_id, COUNT(*) AS COUNT FROM visitor GROUP BY question_id) AS C ON A.id = C.question_id
时间: 2024-10-15 07:51:36