sql - 添加列说明工作人员来自的城市
问题描述
我需要加入一些表格以显示同一记录的 3 个城市列都可以不同。到目前为止我已经得到
- 房产所在的城市
- 物业所在的分公司所在的城市
查询是
select a.propertyNo, a.city as propertyCity, b.city
from PropertyForRent a
inner join Branch b on a.branchNo = b.branchNo
where a.ownerNo = 'CO69'
我需要获取工作人员所在的城市,而不是分支机构编号,并且我不确定如何仅根据当前查询的分支机构编号来实现它。我可以通过自己的查询来获得答案。我只是不确定如何将它与上面的查询结合起来。
select branch.city, * from Staff
inner join Branch on staff.branchNo = branch.branchNo
where staff.staffNo = 'SA9'
解决方案
对现有查询使用 PropertyForRent 的另一个联接
select p.city from Staff s
inner join Branch b
on s.branchNo = b.branchNo
join PropertyForRent p on p.branchNo=b.branchNo
join Branch bb s.branchNo=bb.branchNo
where staff.staffNo = 'SA9'
推荐阅读
- javascript - 为什么这告诉我我的 var 未定义?
- javascript - Stripe.js - 无法更改信用卡输入的背景颜色或高度
- flutter - Flutter state outside State object
- php - 在 ubuntu 上安装 phpmyadmin 后用户 'root'@'localhost' 的访问被拒绝
- javascript - 计算在 C# 和 javascript 之间显示的结果不同
- tensorflow - 使用 tflite_convert 为 Coral 转换 tfLite 的 Frozen 图
- java - 如何使字符串在其他类中可用
- r - 如何在 R 中使用 metafor 为荟萃分析找到单个合并效应大小?
- python - 如何解压列表元组
- python - Python:从字典到 csv,通过值的长度复制键