[英]Select data from 2 tables with linking attribute value of 3rd table
Table payment
has as FK{exchange_order_id}
the id of exchange_order
and payment_info
has as FK{payment_id}
the id of payment
. 表
payment
具有与FK{exchange_order_id}
的id exchange_order
和payment_info
具有作为FK{payment_id}
的id payment
。 So, payment_info and exchange_order don't have any shared attribute, but I need data from them, and that's why I am trying to query them through the payment table which is the only link in-between. 因此, payment_info和exchange_order没有任何共享属性,但是我需要它们的数据,这就是为什么我试图通过付款表(它们之间的唯一链接)来查询它们。
I am trying to pull records for a certain time period, therefore I don't know the payment.id
attribute. 我正在尝试提取特定时间段的记录,因此我不知道
payment.id
属性。
I get error near 'FROM exchange_order eo, payment_info pi JOIN payment p ON p.exchange_order_id = ' at line 6
我
near 'FROM exchange_order eo, payment_info pi JOIN payment p ON p.exchange_order_id = ' at line 6
收到错误
SELECT
eo.amount_proposed as proposed,
eo.amount_realized as realized,
pi.local_fee as fee,
pi.local_market_rate as market_rate,
FROM exchange_order eo, payment_info pi
JOIN payment p ON p.exchange_order_id = eo.id
JOIN payment_info ON p.id = pi.payment_id
WHERE create_time >= UNIX_TIMESTAMP('2015-09-01') AND create_time < UNIX_TIMESTAMP('2015-10-01')
UPDATE: first remove extra ,
after pi.local_market_rate as market_rate
from select statement that is the main reason for the error. 更新:首先从select语句
pi.local_market_rate as market_rate
除去extra ,
这是导致错误的主要原因。
SELECT
eo.amount_proposed as proposed,
eo.amount_realized as realized,
pi.local_fee as fee,
pi.local_market_rate as market_rate
FROM exchange_order eo
JOIN payment p ON p.exchange_order_id = eo.id
JOIN payment_info pi ON p.id = pi.payment_id
WHERE create_time >= UNIX_TIMESTAMP('2015-09-01') AND create_time < UNIX_TIMESTAMP('2015-10-01')
You've got a comma between two table names in this line: 在此行的两个表名之间有一个逗号:
FROM exchange_order eo, payment_info pi
Don't you need a JOIN of some kind with an ON clause of some kind? 您是否不需要某种带有ON子句的JOIN?
You cant write it like that, if you write 你不能这样写
exchange_order eo, payment_info pi
JOIN payment p
to sql it cant know if you mean 到SQL它不知道你的意思
(exchange_order eo, payment_info pi)
JOIN payment p
or 要么
exchange_order eo, (payment_info pi
JOIN payment p)
I am pretty sure you cant use both comma and join in a same FROM in sql. 我很确定您不能同时使用逗号和sql中的相同FROM。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.