sql - 存在函数
问题描述
我正在尝试回答以下查询
编写一个查询,显示所有航班的航班号 (flno)、始发地和目的地,其中存在另一个从目的地返回始发地的航班。
select distinct flno, origin, destination as d from flight
where exists (select flno, destination from flight where origin = d)
前两个答案是正确的,但它给了我更多与问题无关的答案?
飞行表:
解决方案
您需要将条件中的子查询与外部查询相关联。exists
你出现的逻辑似乎是:
select flno, origin, destination
from flight f
where exists (
select 1
from flight f1
where f1.origin = f.destination and f1.destination = f.origin
)
推荐阅读
- javascript - JavaScript 检查是 word 文档是否打开
- android - 当我仅在省电模式下使用插拔 USB 进行测试时,如何避免自动重新启动活动
- selenium - Pytest + 硒。测试网站上的所有链接
- html - HTML,CSS:将按钮内的文本与图像对齐
- c# - 插入 Catia V5 CATDrawing 时保存的 png 图像失去透明度
- python - 自定义记录器不覆盖根日志级别
- apache-kafka - Strimzi kafka 出口商 kafka_consumergroup_members 指标
- java - Java 变量是一台机器上的 Timestamp 和另一台机器上的 LocalDateTime
- visual-studio-2015 - 如何在导航栏中永久显示方法下拉列表?
- azure - Azure AD 用户删除和触发器