mysql - 我们如何创建一个视图,其中表 A 中的 2 个字段都需要表 B 中特定字段的数据?
问题描述
创建一个名为 TripMaps 的新 SQL 视图,其中包括每个 TripID 的起点和终点车站的车站详细信息(地标、纬度、经度)。(Stations.name 和 trips.startstation 包含相似的站名)
解决方案
create or replace view TripMaps as
select
s.Name,
s.CoordLat,
s.CoordLong,
s.Landmark
from Stations s
where s.Name in (Select t.StartStation,t.EndStation from Trips t);
这假设您为 Stations.Name 和 Trips.StartStation / Trips.EndStation 使用具有相同格式的完全相同的名称)
推荐阅读
- c++ - 包含 Bazel http_file 下载的文件
- python - 如何正确设置 Python 套接字服务器
- google-colaboratory - 在 Google Colab 中设置环境变量
- go - 在golang中迭代多个返回
- kotlin - 由于源代码中的多个实现,异步不会编译
- r - 在 stringr 中提取所有内容直到第三个句点
- java - Xerces v2.12.0 XML Schema 1.1 验证
- python - 如何摆脱 Python sympy 中的垂直渐近线?
- enterprise-architect - Enterprise Architect:在创建实例时从初始属性值设置运行状态
- html - 如何在反应语义ui中调整表格组件的大小?