从2个表中选择第3个表的链接属性值的数据

时间:2015-10-06 12:13:02

标签: php mysql

表格payment的{​​{1}} ID为FK{exchange_order_id}exchange_order的ID为payment_infoFK{payment_id}的ID为payment。因此, payment_info exchange_order 没有任何共享属性,但我需要来自他们的数据,这就是我尝试通过付款<查询的原因/ strong> table是中间唯一的链接。

我正在尝试将记录拉出一段时间,因此我不知道payment.id属性。

我收到错误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')

3 个答案:

答案 0 :(得分:1)

更新:首先从select语句,之后删除额外的pi.local_market_rate as market_rate,这是导致错误的主要原因。

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')

答案 1 :(得分:0)

这一行中的两个表名之间有一个逗号:

     FROM exchange_order eo, payment_info pi

您是否需要使用某种类型的ON子句加入某种类型的JOIN?

答案 2 :(得分:0)

如果你写的话,你就不能这样写。

exchange_order eo, payment_info pi
JOIN payment p

到sql它不知道你的意思是

 (exchange_order eo, payment_info pi)
JOIN payment p

 exchange_order eo, (payment_info pi
JOIN payment p)

我很确定你不能同时使用逗号并加入sql中的同一个FROM。