例1:查询某个文章及其对应的评论(单个详情)
SELECT id, name, (SELECT comment_id, title, content FROM B WHERE user_id = A.id ORDER BY create_time DESC LIMIT 1) FROM A;
例2:查询分类表中,每种分类各包含多少商品(汇总)
SELECT category_id, (SELECT count(goods_id) FROM Goods WHERE category_id = A.category_id) FROM category;
时间: 2024-10-11 19:20:02