sql - 这个查询的输出应该是什么
问题描述
显示位于同一地点的销售人员的销售人员 ID、销售人员姓名和位置。
我已经使用自我加入来解决它
select s.sid, s.sname, s.location
from salesman s
inner join salesman ss on s.location = ss.location
where s.location=ss.location
Salesman Table
SID SNAME LOCATION
1 Peter London
2 Michael Paris
3 John Mumbai
4 Harry Chicago
5 Kevin London
6 Alex Chicago
预期产出
Expected Result
SID SNAME LOCATION
5 Kevin London
6 Alex Chicago
1 Peter London
4 Harry Chicago
解决方案
我假设您并不特别关注您在预期输出中显示的序列并使用了更快的连接。
select s.sid, s.sname, s.location
from salesman s
inner join (
select location from salesman group by location having count(*) >1
) ss on s.location = ss.location
推荐阅读
- python - Google Colab 不会显示数据框
- python - 为什么我的 python 格式打印出相同的变量而不是两个变量
- sql - SQL 查询对表的多引用
- string - 计算字符串解决方案中的元音
- xcode - 如何在 SwiftUI 中使用带有结构的 if 语句?
- javascript - 使用 styled-component 将数组渲染到行
- asp.net - ASP.NET_SessionId cookieSameSite 问题
- java - 如何在其成员函数kotlin中调用构造函数?
- cassandra - 如何建模账户逻辑?
- python - Python:请求 POST 方法未将文件上传到 Web 服务器