SQL where 限制
以下是我的输出,我只想显示那些重复的名称。每个名字都是一名飞行员,号码是飞行员驾驶的飞机类型。我想显示驾驶不止一架飞机的飞行员的姓名。我正在使用 sql*plus
PIL_PILOTNAME DEP_EQUIP_NO
------------------------------ ------------
Gladchuk, Chet 1085
Gladchuk, Chet 1345
Green, Edward L. 1489
Harris, Kenneth C. 1253
Leiss, Ernst L. 1194
Long, Stuart 1081
Pasewark, William B. 1026
Pasewark, William B. 1347
Scamell, Richard 1368
我的输出应该只显示:
PIL_PILOTNAME DEP_EQUIP_NO
------------------------------ ------------
Gladchuk, Chet 1085
Gladchuk, Chet 1345
Pasewark, William B. 1026
Pasewark, William B. 1347
这是我的查询:
select distinct pil_pilotname,dep_equip_no from pilots join departures
on dep_pilot_id = pil_pilot_id join equip_type
on eq_equip_no = dep_equip_no
order by pil_pilotname;
Below is my output, I want to display only those names that repeat. Each name is a pilot and the number is the type of airplane the pilot fly's. I want to display the names of pilots who fly more than one airplane. I am using sql*plus
PIL_PILOTNAME DEP_EQUIP_NO
------------------------------ ------------
Gladchuk, Chet 1085
Gladchuk, Chet 1345
Green, Edward L. 1489
Harris, Kenneth C. 1253
Leiss, Ernst L. 1194
Long, Stuart 1081
Pasewark, William B. 1026
Pasewark, William B. 1347
Scamell, Richard 1368
My output should only display:
PIL_PILOTNAME DEP_EQUIP_NO
------------------------------ ------------
Gladchuk, Chet 1085
Gladchuk, Chet 1345
Pasewark, William B. 1026
Pasewark, William B. 1347
Here's my query:
select distinct pil_pilotname,dep_equip_no from pilots join departures
on dep_pilot_id = pil_pilot_id join equip_type
on eq_equip_no = dep_equip_no
order by pil_pilotname;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这会给你你所需要的。 where 中的内部 select 进行过滤。
This will give you what you need. The inner select in the where does the filtering.
在这种情况下,最好的选择是使用分析
In this case the best option would be to use analytics
这两个(或两个)之一应该有效
或者
One of these two (or both) should work
Or
您可以使用
GROUP BY
子句。You can make use of a
GROUP BY
clause.似乎您没有从
equip_type
表中提取任何内容,在这种情况下,您可能不需要加入它。我在这里假设dep_equip_no
是equip_type.eq_equip_no
的外键,因此无法保存equip_type
中找不到的值。考虑到这一点,我的解决方案将如下所示:
基本上,除了删除与
equip_type
的联接之外,我只向返回dep_pilot_id
列表的子选择添加了一个联接具有多个不同关联dep_equip_no
的值。如果您认为查询中需要
equip_type
表,您可以将删除的联接放回去,它应该不会影响结果。Seems like you are not pulling anything from the
equip_type
table, in which case you might not need to join to it. I'm assuming here thatdep_equip_no
is a foreign key toequip_type.eq_equip_no
and thus cannot hold values not found inequip_type
.With that in mind, my solution would look like this:
Basically, apart from removing the join to
equip_type
, I only added one join to a subselect that returns a list ofdep_pilot_id
values having more than one distinct associateddep_equip_no
.If you think you need the
equip_type
table in your query, you can put the removed join back, it should not affect the results.