需要幫助轉移的SQL續集:
SQL:
需要幫助的SQL和Sequel涉及內部連接和地方/過濾器
SELECT table_t.curr_id FROM table_t
INNER JOIN table_c ON table_c.curr_id = table_t.curr_id
INNER JOIN table_b ON table_b.bic = table_t.bic
WHERE table_c.alpha_id = 'XXX' AND table_b.name='Foo';
我被困在續集中,我不知道如何篩選,到目前爲止是這樣的:
cid= table_t.select(:curr_id).
join(:table_c, :curr_id=>:curr_id).
join(:table_b, :bic=>:bic).
filter(?????)
回答更好的成語比上面的讚賞,因爲well.Tnx。
UPDATE:
我要修改一點點,使其工作
cid = DB[:table_t].select(:table_t__curr_id).
join(:table_c, :curr_id=>:curr_id).
join(:table_b, :bic=>:table_t__bic). #add table_t or else ERROR: column table_c.bic does not exist
filter(:table_c__alpha_id => 'XXX',
:table_b__name => 'Foo')
不帶過濾器,
cid = DB[:table_t].select(:table_t__curr_id).
join(:table_c, :curr_id=>:curr_id, :alpha_id=>'XXX').
join(:table_b, :bic=>:table_t__bic, :name=>'Foo')
順便說一下我使用的pgsql 9.0
「續集」是老字號,現在我們稱之爲'SQL':) – Zabba 2010-12-21 14:12:44