mysql查询left join
时间: 2023-10-16 18:10:10 浏览: 94
MySQL中的左连接(left join)是一种连接操作,它返回左表中的所有行,以及满足连接条件的右表中的匹配行。
对于需求1,正确的SQL写法是:
SELECT c.name, count(s.name) as num
FROM classes c
LEFT JOIN students s on s.class_id = c.id and s.gender = 'F'
GROUP BY c.name
这个查询会返回每个班级的名称和女生人数。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [MySQL:Left Join的where和on查询关键字注意!!!](https://blog.csdn.net/qq_38119124/article/details/131281260)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文