sql - 使用 3 个表连接获取 API 列表
问题描述
我有 3 个表,我想从中获取一些数据:
主表:
create table if not exists exchange
(
id bigint,
name varchar(255),
);
INSERT INTO exchange (id, name)
VALUES (1, 'PARIS');
第二张表:
create table exchange_api
(
id bigint,
api_name varchar(255),
exchange_id bigint
);
INSERT INTO exchange_api (id, api_name, exchange_id)
VALUES (8, 'PARIS-API', 5);
第三张表:
create table instrument
(
id bigint,
symbol varchar(255),
exchange_api_id bigint
);
INSERT INTO instrument (id, symbol, exchange_api_id)
VALUES (47, 'PARIS-ARD', 8);
INSERT INTO instrument (id, symbol, exchange_api_id)
VALUES (48, 'PARIS-SRD', 8);
我需要按照以下方式映射表格:
exchange
我要发送参数的第一张桌子PARIS
结果我想得到这个结果:
PARIS-ARD
PARIS-SRD
我怎样才能使用这些数据JOIN
?
解决方案
Select I.symbol from instrument I
inner join exchange_api API
On I.exchange_api_id API.id
Inner JOIN exchange E
ON API.exchange_id = E.id
where E.name = 'PARIS'
如果您想将 Pass 'PARIS'作为值传递,那么它将返回
PARIS-ARD
PARIS-SRD
作为输出
推荐阅读
- select - 从表中选择一个字段时输出值的顺序。SQL 服务器
- php - 如何将 html 形式的数据条目写入服务器上的 .csv 文件?
- javascript - 如何使用 React 映射数组
- excel - Azure Data Studio 生成的 Excel 电子表格将单元格值显示为文本(不是公式执行的结果)
- javascript - 如何在 React 中使用单个调度来调度多个动作?
- c# - c#:如果结果被丢弃,则发出警告
- arangodb - 使用 ArangoSearch LIKE 搜索带空格的字符串
- javascript - 无法从父组件访问 Refs 方法
- amazon-web-services - 无法删除 AWS VPC 终端节点
- jenkins - 从作业执行脚本到 Jenkins 文件系统