そうでなければ複雑な結合の小さな部分を解決しようとして立ち往生しています。
「指示」テーブルと「見積もり」テーブルがあります。「見積もり」にはestimates
、特定の命令のさまざまなタイプの複数の行があります。
指示表
id | address | status
1 | 27 TAYLOR ROAD, ALBION PARK NSW 2527 | InProgress
見積もり表
id | instruction_id | basis | basis_date | basis_value
1 | 1 | ContractPrice | 2012-04-05 | 124000
2 | 1 | CAMV | 2012-02-01 | 120000
3 | 1 | CustomerEstimate | 2012-06-07 | 132000
4 | 1 | ContractPrice | 2013-01-03 | 140000
5 | 1 | CustomerEstimate | 2013-02-09 | 145000
私たちが望むのは、実際には、1) 最新の 'CustomerEstimate' (basis_date とbasis_value を Estimate_date と Estimate_value としてエイリアス化) と 2) の instruction.id = Estimation.instruction_id と assessment.basis に基づく 'estimates' の 'instructions' の 2 つの結合です。最新の 'ContractPrice' (ここでも、basis_date と basic_value を contact_date と contract_value としてエイリアシングします)。
意図した結果は次のようになります。
id | address | status | contract_price | contract_date | estimate_date | estimate_value
1 | 27 TAYLOR ROAD, ALBION PARK NSW 2527 | InProgress | 2013-01-03 | 140000 | 2013-02-09 | 145000
そこにいる SQL の専門家からの支援に本当に感謝しています。
どうもありがとう、トレント。