Table A (org_zip, dest_zip), Table zip(zipcode, city, state) How to get orig_city, orig_state, dest_city, dest_state thanks,
f*g
2 楼
起码应该可以这么干(SQL SERVER) SELECT org.city, org.state, dest.city, dest.state FROM ( (SELECT org_zip, dest_zip, city, state FROM table_A, table_zip WHERE org_zip = zipcode AS org) UNION (SELECT org_zip, dest_zip, city, state FROM table_A, table_zip WHERE dest_zip = zipcode AS dest) ) WHERE org.org_zip = dest.org_zip AND org.dest_zip = dest.dest_zip
【在 m***r 的大作中提到】 : Table A (org_zip, dest_zip), Table zip(zipcode, city, state) : How to get : orig_city, orig_state, dest_city, dest_state : thanks,
c*e
3 楼
try this: select b.city , b.state , c.city , c.state from table_a a , table_b b , table_b c where a.org_zip = b.zipcode and a.dest_zip = c.zipcode
【在 m***r 的大作中提到】 : Table A (org_zip, dest_zip), Table zip(zipcode, city, state) : How to get : orig_city, orig_state, dest_city, dest_state : thanks,
y*w
4 楼
select a.org_zip, ( select state from b where a.org_zip = b.zipcode) as Orig _Sate, a.dst_zip (select state from b where a.dst_zip = b.zipcode) as Dst_ Sate from a same as the last answer. just another way. tested on DB2 UDB.