sql - 如何添加值以在 sql 中计数?
问题描述
我在图像中显示的 ER 图中有以下相关的 SQL 查询。
Select count(distinct(tkey)) as fromAustria
from theses
where ikey in (select ikey
from institutions
right join countries on institutions.cokey = countries.cokey
where countries.name = 'Austria');
我怎样才能检索到这些信息?
目前隶属于奥地利机构的人发表了多少不同的论文和论文?(返回单数)
我总是有不同的论文,但我怎样才能把不同的论文加到计数中呢?
解决方案
你几乎在那里。如果 'papers' 和 'theses' 表之间没有直接的键关系,则需要通过 'authpapers' 表
Select count(distinct(tkey)) as fromAustria, count(distinct(pkey)) as papers
from theses
Left/Inner/right join Authpapers on authpapers.key = theses.key
Left/Inner/right join papers on papers.key = authpapers.key
where ikey in (select ikey
from institutions
right join countries on institutions.cokey = countries.cokey
where countries.name = 'Austria');
推荐阅读
- mysql - 创建新列和比较
- html - 源代码中的换行符在右对齐并使用时呈现为无宽度空白
- python - 合并列、pickup_date 和pickup_time = + 不支持的操作数类型:“DatetimeIndex”和“str”
- node.js - 我可以使用 Mongo DB 设置服务器以使用 three.js 库进行开发吗?
- python - 如何在 pandas 数据帧上生成具有随机值的合成数据?
- android - 我们如何使用 setLaunchDisplayId() 将 Activity 显示为横向?
- spring-boot - Spring Security 5 OpenId 资源服务器 Websecurity dsl
- javascript - JavaScript 中是否有一种方法可以在相对较快的时间内获得大量 BigInt 类型的表示?
- reactjs - 在反应路由器上找不到处理资源
- javascript - Ammap.js 4 - 将地图设置为半静态视图地球 + 将 mapObject 设置为中心