瀏覽單個文章
穩ㄝ
Major Member
 

加入日期: Oct 2005
您的住址: 淡水
文章: 131
搞不懂為什麼又要問key又要問table schema的....以他的問題來說....
即使不知道應該也可以做出來吧....

用group的方式
select p.產品代號, p.產品名稱, sum(s.預估產品數量) as 預估產量, sum(o.訂單數量) as 訂單量
from 產品資料表 p
left outer join 預估資料表 as s on s.產品代號=p.產品代號
left outer join 訂單資料表 as o on o.產品代號=p.產品代號
group by p.產品代號
order by p.產品代號

不用group的方式
select p.產品代號, p.產品名稱,
(select sum(s.預估產品數量) from 預估資料表 as s where s.產品代號=p.產品代號) as 預估數量,
(select sum(o.訂單數量) from 訂單資料表 as o where o.產品代號=p.產品代號) as 訂單量
from 產品資料表 as p
order by p.產品代號
舊 2006-06-30, 10:52 PM #15
回應時引用此文章
穩ㄝ離線中