sqlite - 我有 2 个关于使用 2 个表的 sqlite3 查询的问题
解决方案
对于 A,您需要连接 2 个表,然后group by lecturer, module
计算每个组的行数(每行对应一个学生):
select t.lecturer, t.module, count(*) numberofstudents
from teaches t inner join studies s
on s.module = t.module
group by t.lecturer, t.module
order by t.lecturer
对于 B,使用NOT EXISTS
查找所有成绩所在的模块>= 40
并计算它们:
select count(distinct module) numberofmodules
from studies s
where not exists (
select 1 from studies
where module = s.module and grade < 40
)
推荐阅读
- typescript - 模具是否使用 tsconfig.json?
- git - 如何从 github REST api 获取给定 blob sha 的提交 sha
- python - 有没有一种方便的方法来自动化 HomeAssistent (Hass.io) 备份 / snapsnots?
- arrays - 如何访问 Matlab 结构数组中的某些元素
- spring-boot - springboot 问题从属性文件中读取
- sql - distinct 子句不会产生预期的结果
- android - ViewModel 如何在配置更改中幸存下来
- javascript - 关键字消息删除事件未触发
- python - 如何使用 BeautifulSoup 从 xml 中提取文本和标签属性
- c++ - 在 Windows 上使用 ANGLE 和 GLFW 设置 C++ 项目