日期:2014-05-17  浏览次数:20633 次

A SQL query question for oracle。
物料表:
id name
----------
001 物料1
002 物料2

仓库表:
sid id qty
------------
01 001 2
02 001 3
03 001 5
01 002 1
02 002 2
03 002 4

我期望的查询结果是:
id name sid qty
--------------------
001 物料1 01 2
  02 3
  03 5
002 物料2 01 1
  02 2
  03 4

求各位指点谢谢!

------解决方案--------------------
这样试试……
SQL code
select t1.id ,t1.name,t2.sid,t2.qty 
from (select * from t_wuliao order by id asc)t1 
full join 
(select * from t_cangku  order by id,sid asc)t2
on t1.id=t2.id and t2.sid ='01'